Skip to content

Instantly share code, notes, and snippets.

@rchardptrsn
Created February 1, 2020 18:32
Show Gist options
  • Save rchardptrsn/830d0fbe844be59483aed36946fdc65a to your computer and use it in GitHub Desktop.
Save rchardptrsn/830d0fbe844be59483aed36946fdc65a to your computer and use it in GitHub Desktop.
# Set the Index on Country Name - previously was numeric.
gdp_transpose = gdp.set_index('Country Name')
# Transpose the index and columns
gdp_transpose = gdp_transpose.transpose()
# Reset the index, sets, 'index' as a column
gdp_transpose = gdp_transpose.reset_index()
# Rename the 'index' column to year
gdp_transpose = gdp_transpose.rename(columns={'index':'Year'})
# Set the DataFrame Index to newly named 'Year'
gdp_transpose = gdp_transpose.set_index('Year')
gdp_transpose.head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment