将时间序列组合成具有不同时间实例的单个图
Combining time series into single plot with different time instances
我有一个像下面这样的大数据框,我想从中绘制一个时间序列,显示每个发送者随时间变化的温度线。
utctime sender temp_3
500 2014-10-24 11:21:08 e 24.7
501 2014-10-24 11:21:09 d 22.8
502 2014-10-24 11:21:09 a 23.2
503 2014-10-24 11:21:09 c 24.3
504 2014-10-24 11:21:10 b 23.9
505 2014-10-24 11:21:10 e 24.7
506 2014-10-24 11:21:11 d 22.9
507 2014-10-24 11:21:11 a 23.1
508 2014-10-24 11:21:11 c 24.2
509 2014-10-24 11:21:12 b 23.9
510 2014-10-24 11:21:12 e 24.7
511 2014-10-24 11:21:13 d 22.9
512 2014-10-24 11:21:13 a 23.1
513 2014-10-24 11:21:13 c 24.2
514 2014-10-24 11:21:14 b 23.9
我尝试使用过滤为每个发件人临时工提取一个系列,然后将它们重新组合成一个新的数据帧,但时间都不一样。还有另一种方法吗?我是新手,如有重复,请见谅!
使用pandas.DataFrame.groupby()
方法按发件人分组,然后绘图。
例如:
plotaxis = plt.figure().gca()
for key, grp in dataframe.groupby(['sender']):
my_ts = [ts.to_julian_date() - 1721424.5
for ts in grp['utctime'].dropna()]
plt.plot(my_ts,
grp['temp_3'].dropna(),
label='%s@%s' % (Temperature, key))
# Style the resulting plot
plotaxis.xaxis.set_major_formatter(
matplotlib.dates.DateFormatter('%d/%m/%y\n%H:%M')
)
我有一个像下面这样的大数据框,我想从中绘制一个时间序列,显示每个发送者随时间变化的温度线。
utctime sender temp_3
500 2014-10-24 11:21:08 e 24.7
501 2014-10-24 11:21:09 d 22.8
502 2014-10-24 11:21:09 a 23.2
503 2014-10-24 11:21:09 c 24.3
504 2014-10-24 11:21:10 b 23.9
505 2014-10-24 11:21:10 e 24.7
506 2014-10-24 11:21:11 d 22.9
507 2014-10-24 11:21:11 a 23.1
508 2014-10-24 11:21:11 c 24.2
509 2014-10-24 11:21:12 b 23.9
510 2014-10-24 11:21:12 e 24.7
511 2014-10-24 11:21:13 d 22.9
512 2014-10-24 11:21:13 a 23.1
513 2014-10-24 11:21:13 c 24.2
514 2014-10-24 11:21:14 b 23.9
我尝试使用过滤为每个发件人临时工提取一个系列,然后将它们重新组合成一个新的数据帧,但时间都不一样。还有另一种方法吗?我是新手,如有重复,请见谅!
使用pandas.DataFrame.groupby()
方法按发件人分组,然后绘图。
例如:
plotaxis = plt.figure().gca()
for key, grp in dataframe.groupby(['sender']):
my_ts = [ts.to_julian_date() - 1721424.5
for ts in grp['utctime'].dropna()]
plt.plot(my_ts,
grp['temp_3'].dropna(),
label='%s@%s' % (Temperature, key))
# Style the resulting plot
plotaxis.xaxis.set_major_formatter(
matplotlib.dates.DateFormatter('%d/%m/%y\n%H:%M')
)