0

I am trying to groupie my data based on Year and Month name but the year is getting reflected only in one column. I am trying to get it along all the rows:

three_month_t_bill_df['observation_date'] = pd.to_datetime(three_month_t_bill_df['observation_date'])


three_month_t_bill_df['Month_Number'] = three_month_t_bill_df['observation_date'].dt.month
three_month_t_bill_df['Year'] = three_month_t_bill_df['observation_date'].dt.year
result = three_month_t_bill_df['observation_date'].dt.month_name

three_month_t_bill_df['Month_Name'] = three_month_t_bill_df['Month_Number'].apply(lambda x: calendar.month_name[x])

three_month_t_bill_df_monthly = three_month_t_bill_df.groupby(['Year', 'Month_Name']).agg("mean")

I am getting the following result:

1986    April   6.0625  4.0
        August  5.5780  8.0
        December    5.5100  12.0

... ... ... ...
2021    May 0.0175  5.0
        November    0.0525  11.0
        October 0.0500  10.0
        September   0.0425  9.0

The desired result is:

1986    April   6.0625  4.0
1986    August  5.5780  8.0
1986    December    5.5100  12.0
slayer1996
  • 39
  • 7

0 Answers0