Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Calculating Unit Economics in Python | Unit Economics
Quizzes & Challenges
Quizzes
Challenges
/
Business Analytics and Decision Making with Python

bookCalculating Unit Economics in Python

To effectively analyze your business, you need to calculate and interpret key unit economics metrics: Customer Lifetime Value (LTV), Customer Acquisition Cost (CAC), and Margin. These metrics help you understand how much revenue each customer brings over their relationship with your business, how much it costs to acquire them, and how much profit you retain after costs. Recall the typical formulas:

LTV=Average Revenue per User (ARPU)×Gross Margin (%)×Average Customer Lifespan CAC=Total Marketing and Sales CostsNumber of New Customers Acquired Margin=RevenueCost of Goods SoldRevenue\text{LTV} = \text{Average Revenue per User (ARPU)} \times \text{Gross Margin (\%)} \times \text{Average Customer Lifespan} \\ \ \\ \text{CAC} = \frac{\text{Total Marketing and Sales Costs}}{\text{Number of New Customers Acquired}} \\ \ \\ \text{Margin} = \frac{\text{Revenue} - \text{Cost of Goods Sold}}{\text{Revenue}}

Assume your data is structured in a pandas DataFrame with columns such as customer_id, acquisition_channel, segment, revenue, cost_of_goods_sold, marketing_cost, acquisition_date, and churn_date. This setup allows you to aggregate and segment unit economics by customer characteristics.

1234567891011121314151617181920212223242526272829303132333435363738394041
import pandas as pd # Example customer data data = { 'customer_id': [1, 2, 3, 4, 5], 'revenue': [500, 300, 400, 600, 200], 'cost_of_goods_sold': [300, 180, 220, 350, 120], 'marketing_cost': [50, 40, 60, 70, 30], 'acquisition_date': pd.to_datetime(['2021-01-01', '2021-02-01', '2021-01-15', '2021-03-01', '2021-02-20']), 'churn_date': pd.to_datetime(['2022-01-01', '2021-08-01', '2022-01-15', '2022-03-01', '2021-12-20']) } df = pd.DataFrame(data) # Calculate average lifespan in years df['lifespan_years'] = (df['churn_date'] - df['acquisition_date']).dt.days / 365 # Calculate ARPU (average revenue per user) arpu = df['revenue'].mean() # Calculate gross margin percentage df['gross_margin_pct'] = (df['revenue'] - df['cost_of_goods_sold']) / df['revenue'] avg_gross_margin_pct = df['gross_margin_pct'].mean() # Calculate average customer lifespan avg_lifespan = df['lifespan_years'].mean() # Calculate LTV ltv = arpu * avg_gross_margin_pct * avg_lifespan # Calculate CAC total_marketing_cost = df['marketing_cost'].sum() num_customers = df['customer_id'].nunique() cac = total_marketing_cost / num_customers # Calculate average margin df['margin'] = (df['revenue'] - df['cost_of_goods_sold']) / df['revenue'] avg_margin = df['margin'].mean() print(f"Average LTV: {ltv:.2f}") print(f"Average CAC: {cac:.2f}") print(f"Average Margin: {avg_margin:.2%}")
copy
1234567891011121314151617
# Segmenting unit economics by acquisition channel or customer segment # Suppose you add 'acquisition_channel' and 'segment' columns df['acquisition_channel'] = ['Organic', 'Paid', 'Organic', 'Referral', 'Paid'] df['segment'] = ['SMB', 'Enterprise', 'SMB', 'Enterprise', 'SMB'] # Group by acquisition channel and calculate metrics channel_group = df.groupby('acquisition_channel').agg( arpu=('revenue', 'mean'), gross_margin_pct=('gross_margin_pct', 'mean'), avg_lifespan=('lifespan_years', 'mean'), cac=('marketing_cost', 'mean'), avg_margin=('margin', 'mean') ) channel_group['ltv'] = channel_group['arpu'] * channel_group['gross_margin_pct'] * channel_group['avg_lifespan'] print(channel_group[['arpu', 'gross_margin_pct', 'avg_lifespan', 'ltv', 'cac', 'avg_margin']])
copy

When you segment unit economics by acquisition channel or customer segment, you can spot significant differences in profitability and efficiency. For instance, if customers acquired through organic channels have higher LTV and lower CAC compared to paid channels, this suggests organic growth is more cost-effective. Conversely, if a particular segment has a lower margin, it might indicate higher costs or less pricing power in that group. These insights allow you to prioritize channels and segments that drive sustainable growth, optimize marketing spend, and refine your targeting strategies. Always interpret unit economics in context—variations may stem from different customer behaviors, product mixes, or marketing approaches.

question mark

Which of the following best describes what you should do if you find that the CAC for your 'Paid' channel is higher than the LTV for customers acquired through that channel?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 2

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

bookCalculating Unit Economics in Python

Свайпніть щоб показати меню

To effectively analyze your business, you need to calculate and interpret key unit economics metrics: Customer Lifetime Value (LTV), Customer Acquisition Cost (CAC), and Margin. These metrics help you understand how much revenue each customer brings over their relationship with your business, how much it costs to acquire them, and how much profit you retain after costs. Recall the typical formulas:

LTV=Average Revenue per User (ARPU)×Gross Margin (%)×Average Customer Lifespan CAC=Total Marketing and Sales CostsNumber of New Customers Acquired Margin=RevenueCost of Goods SoldRevenue\text{LTV} = \text{Average Revenue per User (ARPU)} \times \text{Gross Margin (\%)} \times \text{Average Customer Lifespan} \\ \ \\ \text{CAC} = \frac{\text{Total Marketing and Sales Costs}}{\text{Number of New Customers Acquired}} \\ \ \\ \text{Margin} = \frac{\text{Revenue} - \text{Cost of Goods Sold}}{\text{Revenue}}

Assume your data is structured in a pandas DataFrame with columns such as customer_id, acquisition_channel, segment, revenue, cost_of_goods_sold, marketing_cost, acquisition_date, and churn_date. This setup allows you to aggregate and segment unit economics by customer characteristics.

1234567891011121314151617181920212223242526272829303132333435363738394041
import pandas as pd # Example customer data data = { 'customer_id': [1, 2, 3, 4, 5], 'revenue': [500, 300, 400, 600, 200], 'cost_of_goods_sold': [300, 180, 220, 350, 120], 'marketing_cost': [50, 40, 60, 70, 30], 'acquisition_date': pd.to_datetime(['2021-01-01', '2021-02-01', '2021-01-15', '2021-03-01', '2021-02-20']), 'churn_date': pd.to_datetime(['2022-01-01', '2021-08-01', '2022-01-15', '2022-03-01', '2021-12-20']) } df = pd.DataFrame(data) # Calculate average lifespan in years df['lifespan_years'] = (df['churn_date'] - df['acquisition_date']).dt.days / 365 # Calculate ARPU (average revenue per user) arpu = df['revenue'].mean() # Calculate gross margin percentage df['gross_margin_pct'] = (df['revenue'] - df['cost_of_goods_sold']) / df['revenue'] avg_gross_margin_pct = df['gross_margin_pct'].mean() # Calculate average customer lifespan avg_lifespan = df['lifespan_years'].mean() # Calculate LTV ltv = arpu * avg_gross_margin_pct * avg_lifespan # Calculate CAC total_marketing_cost = df['marketing_cost'].sum() num_customers = df['customer_id'].nunique() cac = total_marketing_cost / num_customers # Calculate average margin df['margin'] = (df['revenue'] - df['cost_of_goods_sold']) / df['revenue'] avg_margin = df['margin'].mean() print(f"Average LTV: {ltv:.2f}") print(f"Average CAC: {cac:.2f}") print(f"Average Margin: {avg_margin:.2%}")
copy
1234567891011121314151617
# Segmenting unit economics by acquisition channel or customer segment # Suppose you add 'acquisition_channel' and 'segment' columns df['acquisition_channel'] = ['Organic', 'Paid', 'Organic', 'Referral', 'Paid'] df['segment'] = ['SMB', 'Enterprise', 'SMB', 'Enterprise', 'SMB'] # Group by acquisition channel and calculate metrics channel_group = df.groupby('acquisition_channel').agg( arpu=('revenue', 'mean'), gross_margin_pct=('gross_margin_pct', 'mean'), avg_lifespan=('lifespan_years', 'mean'), cac=('marketing_cost', 'mean'), avg_margin=('margin', 'mean') ) channel_group['ltv'] = channel_group['arpu'] * channel_group['gross_margin_pct'] * channel_group['avg_lifespan'] print(channel_group[['arpu', 'gross_margin_pct', 'avg_lifespan', 'ltv', 'cac', 'avg_margin']])
copy

When you segment unit economics by acquisition channel or customer segment, you can spot significant differences in profitability and efficiency. For instance, if customers acquired through organic channels have higher LTV and lower CAC compared to paid channels, this suggests organic growth is more cost-effective. Conversely, if a particular segment has a lower margin, it might indicate higher costs or less pricing power in that group. These insights allow you to prioritize channels and segments that drive sustainable growth, optimize marketing spend, and refine your targeting strategies. Always interpret unit economics in context—variations may stem from different customer behaviors, product mixes, or marketing approaches.

question mark

Which of the following best describes what you should do if you find that the CAC for your 'Paid' channel is higher than the LTV for customers acquired through that channel?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 2
some-alt