I have a pandas dataframe which looks like as follows:
df =
COLUMN_NAME YEAR1 YEAR2 VALUE
0 Column1 2013 2014 0.042835
1 Column1 2014 2015 0.033600
2 Column2 2013 2014 0.004406
3 Column2 2014 2015 0.016900
...
Where for each COLUMN_NAME, YEAR1 and YEAR2, a VALUE is calculated. I want to group the dataframe such that is it unique on COLUMN_NAME, where the columns look like the following:
df_desired =
COLUMN_NAME Value_from_2013_2014 Value_from_2014_2015 ...
0 Column1 0.042835 0.033600
1 Column2 0.004406 0.016900
...
I can achieve sort of what I want with the code below, but it creates a MultiIndex columns, how can I achieve this? Thanks for the help.
pd.pivot_table(df, 'VALUE', 'COLUMN_NAME', ['YEAR1', 'YEAR2'])
YEAR1 2013 2014
YEAR2 2014 2015
COLUMN_NAME
Column1 0.042835 0.0336
Column2 0.004406 0.0169