Calculating 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=Number of New Customers AcquiredTotal Marketing and Sales Costs Margin=RevenueRevenue−Cost of Goods SoldAssume 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.
1234567891011121314151617181920212223242526272829303132333435363738394041import 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%}")
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']])
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.
Дякуємо за ваш відгук!
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Awesome!
Completion rate improved to 5.56
Calculating 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=Number of New Customers AcquiredTotal Marketing and Sales Costs Margin=RevenueRevenue−Cost of Goods SoldAssume 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.
1234567891011121314151617181920212223242526272829303132333435363738394041import 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%}")
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']])
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.
Дякуємо за ваш відгук!