Session Ready
Exercise

Reshaping for analysis

This exercise starts off with fractions_change and hosts already loaded.

Your task here is to reshape the fractions_change DataFrame for later analysis.

Initially, fractions_change is a wide DataFrame of 26 rows (one for each Olympic edition) and 139 columns (one for the edition and 138 for the competing countries).

On reshaping with pd.melt(), as you will see, the result is a tall DataFrame with 3588 rows and 3 columns that summarizes the fractional change in the expanding mean of the percentage of medals won for each country in blocks.

Instructions
100 XP
  • Create a DataFrame reshaped by reshaping the DataFrame fractions_change with pd.melt().
  • You'll need to use the keyword argument id_vars='Edition' to set the identifier variable.
  • You'll also need to use the keyword argument value_name='Change' to set the measured variables.
  • Print the shape of the DataFrames reshaped and fractions_change. This has been done for you.
  • Create a DataFrame chn by extracting all the rows from reshaped in which the three letter code for each country ('NOC') is 'CHN'.
  • Print the last 5 rows of the DataFrame chn using the .tail() method. This has been done for you, so hit 'Submit Answer' to see the results!