Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara CAC 2/2 | Becoming an Analyst
Introduction to Python for Data Analysis

book
CAC 2/2

CAC formula:

To write numbers in 0.0 format, use the next code round(number, 1).

Compito

Swipe to start coding

  1. Create the expenses variable by finding the sum of all cost. values. Use the .sum() function.
  2. Find the number of rows in the df and put this value into the customers_number variable.
  3. Define the CAC variable using the formula.
  4. Print the CAC variable in the 0.00 format.

Soluzione

import pandas as pd

df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/783d7288-e86b-4b89-9966-a2fe97995277/section_3_dataset_upd.csv')

# Sum all expenses
expenses = df['cost'].sum()
# Find the number of rows
customers_number = df.shape[0]
# Define the CAC variable
CAC = expenses/customers_number
# Print the CAC value in 0.00 format
print('CAC =', round(CAC, 2))

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 4. Capitolo 5
import pandas as pd

df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/783d7288-e86b-4b89-9966-a2fe97995277/section_3_dataset_upd.csv')

# Sum all expenses
expenses = ___['cost'].___()
# Find the number of rows
customers_number = ___.shape[0]
# Define the CAC variable
CAC = ___/___
# Print the CAC value in 0.00 format
___('CAC =', ___(___, 2))

Chieda ad AI

expand
ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

some-alt