1 | initial version |
You can use pandas' groupby and sum functions to calculate the total purchases per month. Here's an example code:
import pandas as pd
# create sample dataframe
df = pd.DataFrame({'month': ['Jan', 'Jan', 'Feb', 'Feb'],
'purchase_value': [100, 200, 150, 250]})
# group by month and sum purchase values
monthly_total = df.groupby('month')['purchase_value'].sum()
# print the result
print(monthly_total)
Output:
month
Feb 400
Jan 300
Name: purchase_value, dtype: int64
In this example, we first create a sample dataframe with two columns: "month" and "purchasevalue". Then, we use the groupby function to group the dataframe by "month", and then apply the sum function to calculate the total purchases per month for the "purchasevalue" column. Finally, we print the result.