Last active
December 20, 2015 13:09
-
-
Save tkb/6136929 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
#read the normalized CSV file | |
df = pandas.read_csv('lifeexpectancy.csv') | |
#melt the normalized file, hold the country name and code variables, rename the melted columns | |
le = pd.melt(df, id_vars=['Country Name','Country Code'], var_name="year", value_name="life_expectancy") | |
#sort by country name for convenience | |
le2 = le.sort(['Country Name']) | |
#write out the csv without and index | |
le2.to_csv('lifeexpectancy-unpivoted.csv', sep=',', index=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment