0
df = pd.read_csv("wind_data.csv")
df = df[['SETTLEMENTDATE', 'wind']].copy()

dataset = df.set_index("SETTLEMENTDATE")
dataset.index = pd.to_datetime(dataset.index)
print(dataset.head())
print(dataset.shape)

Dataset

enter image description here

In this dataset I want to calculate wind data for each month. (I need only 12 rows of this data set instead 105350)

Can you please help me?

  • For the wind stats, do you want average, max, min? or something more complex? I think you can use groupby and pd.grouper as outlined in this answer: https://stackoverflow.com/questions/24082784/pandas-dataframe-groupby-datetime-month or the resample method highlighted by ansev already. – Burgertron May 10 '22 at 13:44

2 Answers2

2

Use DataFrame.resample:

dataset.resample('M')['wind'].sum()
ansev
  • 30,322
  • 5
  • 17
  • 31
0

One way using a groupby:

df = pd.read_csv("wind_data.csv")
df = df[['SETTLEMENTDATE', 'wind']].copy()

dataset['SETTLEMENTMONTH'] = pd.to_datetime(dataset['SETTLEMENTDATE']).dt.floor('M')

dataset.groupby('SETTLEMENTMONTH')['wind'].sum()
Learning is a mess
  • 7,479
  • 7
  • 35
  • 71