I want to do like this How do I create a new column from the output of pandas groupby().sum()?
as show in the high scored answer, df['Data4'] = f['Data3'].groupby(df['Date']).transform('sum')
however, I want to groupby two columns.
thanks
I want to do like this How do I create a new column from the output of pandas groupby().sum()?
as show in the high scored answer, df['Data4'] = f['Data3'].groupby(df['Date']).transform('sum')
however, I want to groupby two columns.
thanks
You can do df['Data4'] = df.groupby(['Date', 'second_grouping_column'])['Data3'].transform('sum')
. As you can see on this page, the groupby method can take a list of columns