IniziaInizia gratis

Calculating means by category

A good way to explore categorical variables further is to calculate summary statistics for each category. For example, you can calculate the mean and median of your response variable, grouped by a categorical variable. As such, you can compare each category in more detail.

Here, you'll look at grouped means for the house prices in the Taiwan real estate dataset. This will help you understand the output of a linear regression with a categorical variable.

taiwan_real_estate is available as a pandas DataFrame.

Questo esercizio fa parte del corso

Introduction to Regression with statsmodels in Python

Visualizza il corso

Istruzioni dell'esercizio

  • Group taiwan_real_estate by house_age_years and calculate the mean price (price_twd_msq) for each age group. Assign the result to mean_price_by_age.
  • Print the result and inspect the output.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# Calculate the mean of price_twd_msq, grouped by house age
mean_price_by_age = ____.____(____)[____].____

# Print the result
print(____)
Modifica ed esegui il codice