BaşlayınÜcretsiz Başlayın

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.

Bu egzersiz

Introduction to Regression with statsmodels in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • 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.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

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

# Print the result
print(____)
Kodu Düzenle ve Çalıştır