I am fairly new to Python, I am trying to convert the Series coming out from groupby() into a dataframe, that I will merge to the main df. However, to_frame() seems not working as it keeps returning a series not a dataframe.Any help will be greatly appreciated See following code:
IN: pf_avg = df.groupby('release_year').profit.mean()
pf_avg.to_frame()
type(pf_avg)
OUT: pandas.core.series.Series
IN: df_pf_avg = df.merge(pf_avg, left_on= 'release_year', right_index= True)
df_pf_avg.head()
OUT: ValueError: can not merge DataFrame with instance of type <class
'pandas.core.series.Series'>