Search⌘ K
AI Features

Data Exploration: Customer Revenue Analysis

Explore how to analyze customer revenue over time by preparing and aggregating transaction data for cohort analysis. Learn to handle missing data and visualize monthly sales trends to better understand customer purchasing behavior and prepare data for predictive models.

In this lesson, we’ll continue our exploration of the online transaction dataset. We’ll transform the dataset for cohort analysis by grouping customers who made their first purchase in the same month.

Aggregate monthly transactions

Let's prepare the base and aggregate month-over-month total sales for each customer.

Python
# aggregate monthly revenue for each customer
df_monthly_sales = df_cdnow_tr.groupby(['customer_id', 'year_month']).agg({'price': 'sum'})
df_monthly_sales.reset_index(inplace=True)
print(df_monthly_sales.head())

Explanation

  • In line 2, we aggregate monthly revenue for each customer.

  • In line 4, we reset the index ...