绘制时间戳列与 Python 中的另一列



我是.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()

它给我错误"类型错误:无效的类型升级">

我相信

需要先使用参数format to_datetime,然后对于15Min数据,请使用mean之类的函数添加resample

df['date'] = pd.to_datetime(df['date'], format='%d/%m/%Y %H:%M')
s = df.resample('15Min', on='date')['temp'].mean()
s.plot()

最新更新