dogs.pivot_table(values=“weight_kg”, index=“color”)
dogs_height_by_breed_vs_color = dog_pack.pivot_table(values=“height_cm”, index=“breed”, columns=“color”)
print(dogs_height_by_breed_vs_color)
dogs_height_by_breed_vs_color.loc[“Chow Chow” : “Poodle”]
dogs_height_by_breed_vs_color.mean(axis=“index”)
dogs_height_by_breed_vs_color.mean(axis=“columns”)
temperatures["year"] = temperatures["date"].dt.year # Add a year column to temperatures
temp_by_country_city_vs_year = temperature.pivot_table(values="avg_temp_c", index=["country", "city"], columns="year") # Pivot avg_temp_c by country and city vs year
print(temp_by_country_city_vs_year)
temp_by_country_city_vs_year.loc["Egypt" : "India"] # Subset for Egypt to India
temp_by_country_city_vs_year.loc[("Egypt","Cairo") : ("India","Delhi")] # Subset for Egypt, Cairo to India, Delhi
temp_by_country_city_vs_year.loc[("Egypt","Cairo") : ("India","Delhi"), "2005": "2010"] # Subset in both directions at once
mean_temp_by_year = temp_by_country_city_vs_year.mean(axis="index") # Get the worldwide mean temp by year
print(mean_temp_by_year[mean_temp_by_year == mean_temp_by_year.max()]) # Filter for the year that had the highest mean temp
mean_temp_by_city = temp_by_country_city_vs_year.mean(axis="columns") # Get the mean temp by city
print(mean_temp_by_city[mean_temp_by_city == mean_temp_by_city.min()]) # Filter for the city that had the lowest mean temp