我是.xls文件,我有时间戳列,时间戳格式如下
2018-04-01 00:01:45
2018-04-01 00:16:45
2018-04-01 00:31:46
2018-04-01 00:46:45
2018-04-01 01:01:46
2018-04-01 01:16:45
2018-04-01 01:31:50
2018-04-01 01:46:45
2018-04-01 02:01:46
我在温度名称的相同.xls文件中有另一列,格式如下
34
34
34
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
我想绘制价值与时间的关系。我试图绘制它,但我在绘制它时遇到问题,因为它没有正确读取时间戳
我的代码:
#changing timestamp data from object to datatype
w = df['Timestamp']
// column name "Timestamp" was creating issue so i have to remove it"
w=w.drop(w.index[0])
//converting timestamp type object to datetime
w = pd.to_datetime(w)
area = (12 * np.random.rand(N))**2 # 0 to 15 point radii
plt.xlabel('Temperature')
plt.ylabel('DateTime')
plt.title('Temperature and DateTime Relation')
plt.scatter(t, w, s=area, c='purple', alpha=0.5)
plt.show()
它给我错误“TypeError:无效的类型提升”
答案 0 :(得分:0)
我认为首先需要to_datetime
参数format
然后才需要15Min
数据添加resample
mean
之类的函数:
df['date'] = pd.to_datetime(df['date'], format='%d/%m/%Y %H:%M')
s = df.resample('15Min', on='date')['temp'].mean()
s.plot()