Using pivot_table to change the unit of analysis of a DataFrame
We could have used the pandas pivot_table function instead of groupby in the previous recipe. pivot_table can be used to generate summary statistics by the values of a categorical variable, just as we did with groupby. The pivot_table function can also return a DataFrame, as we will see in this recipe.
Getting ready
We will work with the COVID-19 case daily data and the Brazil land temperature data again. The temperature data has one row per month per weather station.
How to do it...
Let’s create a DataFrame from the COVID-19 data that has the total number of cases and deaths for each day across all countries:
- We start by loading the COVID-19 and temperature data again:
import pandas as pd coviddaily = pd.read_csv("data/coviddaily.csv", parse_dates=["casedate"]) ltbrazil = pd.read_csv("data/ltbrazil.csv") - Now, we are ready to call the...