How to create a plot using instead of 8760 hours 365 days and 52 weeks in Python

Question:

I am new to Python and am having trouble with a small task. I have a time series with 8760 hours and certain values. I have already split the course of the values for one year. But now I want to plot the course of the values both weekly and daily. Can you help me with this? I would be very grateful


| timestep |   value  |
| -------- | -------- |
| 1        |    …     |
| 2
  …
| 8760     |    …     |

Asked By: momo

||

Answers:

You have to create a new dataframe by calculate the average of the hours. For example, daily will be 24 hours.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

path = "" #Your path
df = pd.read_csv (path+"data.csv")

daily=df.groupby(np.arange(len(df))//24).mean()

plt.plot(daily['timestep'],daily['value'])
plt.show()

For weekly, just change 24 to 24*7.

Answered By: xiaochuan fang