输入:
'''
Created on 2018年12月12日
@author: hcl
'''
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
file_path = 'Realtime_TH.csv'
msg = pd.read_csv(file_path)
# print(msg.shape) #(1917, 6)
# print(msg.head())
# print(msg.tail())
X = range(msg.shape[0])
Y = msg['Temp']
plt.plot(X,Y)
plt.show()
结果:
将其按照时间绘制
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.dates import datestr2num,DateFormatter
import matplotlib.dates as dates
file_path = 'Realtime_TH.csv'
msg = pd.read_csv(file_path)
Y = msg['Temp']
datess = msg['Time']
fig,ax=plt.subplots()
formatter = DateFormatter('%H')
#设置时间间隔
ax.xaxis.set_major_locator(dates.HourLocator(byhour=range(24), interval=1))
ax.xaxis.set_major_formatter(formatter)
ax.plot_date(datess,Y,'-',label='iops')
plt.show()
输出:
输入:
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.dates import datestr2num,DateFormatter
import matplotlib.dates as dates
# file_path = 'Realtime_TH.csv'
file_path = 'Realtime_NS.csv'
msg = pd.read_csv(file_path)
print(msg.head())
Y = msg['Temp']
Y_2 = msg['Hum']
datess = msg['Time']
fig,ax=plt.subplots()
formatter = DateFormatter('%H')
#设置时间间隔
ax.xaxis.set_major_locator(dates.HourLocator(byhour=range(24), interval=1))
ax.xaxis.set_major_formatter(formatter)
ax.plot_date(datess,Y,'-',label='NH3')
ax.plot_date(datess,Y_2,'-',label='H2S')
plt.legend() # 显示图例
plt.show()
按照时间绘制NH3 H2S图片
环境数据异常值剔除
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.dates import datestr2num,DateFormatter
import matplotlib.dates as dates
# file_path = 'Realtime_TH.csv'
file_path = 'Realtime_NS.csv'
msg = pd.read_csv(file_path)
print(msg.shape)
#寻找异常值索引
except_index = msg[msg['Hum'] > 1000].index.tolist()
except_index2 = msg[msg['Temp'] > 1000].index.tolist()
msg = msg.drop(list(set(except_index).union(set(except_index2))))
msg.reset_index()
print(list(set(except_index).union(set(except_index2))))
print(msg.shape)
# print(msg[msg['Hum'] > 1000])
# print(msg.describe())
# print(msg.drop(msg['Temp'] > 1000))
# print(msg[msg['Hum'] > 1000])
Y = msg['Temp']
Y_2 = msg['Hum']
datess = msg['Time']
fig,ax=plt.subplots()
formatter = DateFormatter('%H')
#设置时间间隔
ax.xaxis.set_major_locator(dates.HourLocator(byhour=range(24), interval=1))
ax.xaxis.set_major_formatter(formatter)
ax.plot_date(datess,Y,'-',label='NH3')
ax.plot_date(datess,Y_2,'-',label='H2S')
plt.legend() # 显示图例
plt.show()
输出:
(1413, 6)
[451, 454, 456, 786, 802, 746, 690]
(1406, 6)
绘制箱型图
输入:
import pandas as pd
import matplotlib.pyplot as plt
file_path = 'Realtime_TH.csv'
# file_path = 'Realtime_NS.csv'
msg = pd.read_csv(file_path)
msg.boxplot()
plt.legend() # 显示图例
plt.show()
下图的temp和hum分别表示nh3 h2s (因为在在存储数时,表头设置错误了)