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.
Latihan ini adalah bagian dari kursus
Introduction to Regression with statsmodels in Python
Petunjuk latihan
- Group
taiwan_real_estatebyhouse_age_yearsand calculate the mean price (price_twd_msq) for each age group. Assign the result tomean_price_by_age. - Print the result and inspect the output.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# Calculate the mean of price_twd_msq, grouped by house age
mean_price_by_age = ____.____(____)[____].____
# Print the result
print(____)