0

I've been stuck on this problem for two days. Below is the csv file.

df = pd.read_csv('/14100017.csv')
df = pd.DataFrame(data)
df.head()
df_year = df.groupby('REF_DATE')['REF_DATE'].count()
print(df_year)

This is my code. Could you please tell me or give me a hint or show me the website has similar questions. How to convert monthly employment data into annual by taking average? This is so confused.

Thank you very much! Much appreciated

I tried search similar questions in reddit forum and Stack overflow, they all used rsample and get the result.

Bushmaster
  • 4,196
  • 3
  • 8
  • 28

1 Answers1

2

Just convert REF_DATE to datetime and then extract year:

df['date'] = pd.to_datetime(df['REF_DATE'])
df['year'] = pd.DatetimeIndex(df['date']).year

After, you need to aggregate the value by year:

monthly_year_avg = df.groupby('year')['VALUE'].mean()
Asimandia
  • 248
  • 2
  • 5