I have a dataframe, hourly_subset_df
where
hourly_subset_df.columns = ['date', 'metadata.campaignName', 'localSpend.amount', 'daily_cap']
It contains different ad campaigns with their corresponding spend values per hour of the day.
I want to do a cumulative sum per group such that I can see, for each campaign, the evolution of spend throughout the day.
I've tried doing:
hourly_subset_df['cumsum'] = hourly_subset_df.groupby(['metadata.campaignName', 'date', 'daily_cap'])['localSpend.amount'].cumsum()
and
hourly_subset_df.groupby(['metadata.campaignName', 'date', 'daily_cap'])['localSpend.amount'].transform(pd.Series.cumsum)
based on other answer I found here (this, this).
There results I get back is just a copy of the spend column ('localSpend.amount') instead of a cumulative sum across the unique group of ['metadata.campaignName', 'date', 'daily_cap']
.
Why is this not working?
EDIT: I've created the sample dataframe as a dict here (was too large to paste here).