Reputation: 471
I have a large dataframe like the one below, from which I want to plot a time series showing a line for the temperature from each sender over time.
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
I tried using filtering to pull out a Series for each sender temps, and then recombining these into a new dataframe, but the times are all different. Is there another way to do this? I'm new to this, so apologise if this is a repeat!
Upvotes: 1
Views: 129
Reputation: 2448
Use pandas.DataFrame.groupby()
method to group by sender, then plot.
As an example:
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')
)
Upvotes: 1