import pandas as pd
import matplotlib.pyplot as plt
# 支持中文
plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号
read_df = pd.read_csv('winequality-red.csv',sep=';')
white_df = pd.read_csv('winequality-white.csv',sep=';')
white_df.head()
read_df.head()
import numpy as np
# 为红葡萄酒数据框创建颜色数组
color_red = np.repeat(0,read_df.shape[0])
# 为白葡萄酒数据框创建颜色数组
color_white = np.repeat(1,white_df.shape[0])
read_df['color'] = color_red
white_df['color'] = color_white
wine_df = read_df.append(white_df)
wine_df.info()
wine_df.to_csv('winequality_edited.csv',index=False)
wine_df.to_csv('winequality_edited1.csv')
# 固定酸度
wine_df['fixed acidity'].plot(kind='hist');
# 总二氧化硫
wine_df['total sulfur dioxide'].plot(kind='hist');
# pH 值
wine_df['pH'].plot(kind='hist');
# 酒精度
wine_df['alcohol'].plot(kind='hist');
# 0 红色葡萄酒平均质量 5.636023 1 白色葡萄酒平均质量 5.877909
wine_df.groupby('color').mean()['quality']
wine_df.describe()
def dtype(x):
if x <3.11:
return '高'
elif x <= 3.21:
return '中等偏高'
elif x <= 3.32:
return '中'
else:
return '低'
wine_df['temp'] = wine_df['pH'].map(lambda x:dtype(x))
wine_df.groupby('temp').mean()['quality']
import numpy as np
import pandas as pd
# % matplotlib inline
import pymongo
import matplotlib.pyplot as plt
# 支持中文
plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号
myclient = pymongo.MongoClient("mongodb://localhost:13300/")
bj_itpsdsc = myclient.get_database('bj')
phm_analysis_proproblem = bj_itpsdsc.phm_analysis_proproblem
devCodeMapDF = pd.read_excel('设备种类编码映射.xlsx')
devCodeMap={}
for i in range(devCodeMapDF.shape[0]):
devCodeMap[devCodeMapDF.iloc[i]['种类编码']]=devCodeMapDF.iloc[i]['设备种类']
proproblem = phm_analysis_proproblem.find({})
proproblemDF=pd.DataFrame(list(proproblem))
proproblemDF['devCodeMap'] = proproblemDF['devCode'].map(lambda x: devCodeMap[int(x)])
devCodeCounts = proproblemDF['devCodeMap'].value_counts()
devCodeCounts
import matplotlib
fig =proproblemDF['devCode'].value_counts().plot(title='缺陷设备种类分类数量直方图',kind='bar')
fig.get_figure().savefig('缺陷设备种类分类数量直方图(无中文).png')
fig = proproblemDF['devCodeMap'].value_counts().plot(title='缺陷设备种类分类数量直方图', kind='bar',figsize=(16,6))
fig.get_figure().savefig('缺陷设备种类分类数量直方图.png')
fig = proproblemDF['devCodeMap'].value_counts().plot(title='缺陷设备种类分类饼图', kind='pie',figsize=(10,9));
fig.get_figure().savefig('缺陷设备种类分类饼图.png')
结果文档