I have the following data (below)
{'Country Name': {0: 'China', 1: 'China', 2: 'China'}, 'Country Code': {0: 'CHN', 1: 'CHN', 2: 'CHN'}, 'Series Name': {0: 'Consumer price index (2010 = 100)', 1: 'Age dependency ratio (% of working-age population)', 2: 'Age dependency ratio, old (% of working-age population)'}, '1972 [YR1972]': {0: '..', 1: '79.4811770762984', 2: '6.7804365054766'}, '1973 [YR1973]': {0: '..', 1: '78.8312385191076', 2: '6.83482919991518'}}
My desired output, having dropped the stub names on the years and reshaped to long-format
desired_output = pd.DataFrame({'Country Code': ['CHN', 'CHN'], 'Country Name' : ['China', 'China'],
'Year': ['1972', '1973'],
'Age dependency ratio' : ['79.4811770762984', '78.8312385191076' ],
'Age dependency ratio, old' : ['6.7804365054766', '6.83482919991518']})
I tried,
df.pivot(index = ['Country Name', 'Country Code'], columns = 'Series Name', values = ['1972 [YR1972]', '1973 [YR1973]'])
And it worked but still wasn't in the format I wanted.
As for removing the suffix, really can't figure it out, as it varies by year.