Skip to content
Data Manipulation with pandas
Data Manipulation with pandas
Run the hidden code cell below to import the data used in this course.
Hidden code
Pivot tables
Z kolumny date wyciągamy year i dodajemy kolumne year do tabeli temperatures
temperatures["year"] = temperatures["date"].dt.year
-
Tworzymy tabelę "temp_by_country_city_vs_year": tworzymy pivota z tabeli temperatures, nazywamy ją "avg_temp_c", jako wiersze ustawiamy "country" i "city", a jako wartości dla wierszy grupujemy po kolumnie "year"
temp_by_country_city_vs_year = temperatures.pivot_table("avg_temp_c", index = ["country", "city"], columns = "year")
print(temp_by_country_city_vs_year)