Wasswa Samuel
Wasswa Samuel

Reputation: 2179

Plot time series matplotlib with lots of data points

I want to plot a time series for a dataset which has data for 12 months. However the data is recorded for every hour of every day for the 12months. The whole dataset is over 8000 datapoints. The data is in the following format

        Date   Time  Energy
0 2014-01-01   1     1118.1
1 2014-01-01   2     1233.2
2 2014-01-01   3     1278.2
.     .        .      .  
23 2014-01-01  24    1125.3
24 2014-01-02  1     1213.3
.    .         .      .

When I plot it like this

plt.plot(energy['Date'], energy['Energy'])
plt.xlabel('Date')
plt.ylabel('Energy')

I get the following output time series

This graph doesn't make much sense because I cant observe any trends. I instead want to plot the average energy for each day. Any other suggestions about how to plot this time series in such a way that I observe any trends is welcome

Upvotes: 2

Views: 1728

Answers (2)

jezrael
jezrael

Reputation: 862571

You need groupby with aggregating mean first:

energy = energy.groupby('Date')['Energy'].mean()

and then Series.plot:

energy.plot()

All together:

energy.groupby('Date')['Energy'].mean().plot()

Upvotes: 3

piRSquared
piRSquared

Reputation: 294228

IIUC:

you need to sort

energy = energy.sort_values(['Date', 'Time'])
plt.plot(energy['Date'], energy['Wind Generation'])
plt.xlabel('Date')
plt.ylabel('Energy')
plt.autofmt_xdate()

Upvotes: 1

Related Questions