I have a situation where I need to transform my row level data to column level. The unique identifier on which this dataset lays consists of recurrent values. The dataset looks like this :
ID Rating Rating_Year
1 A 2016
1 B 2017
1 C 2018
2 D 2017
2 E 2018
Now I need to transpose the column Rating_year as
Rating_year_2016 Rating_year_2017 Rating_year_2018
and get the final output as :
ID Rating_Year_2016 Rating_Year_2017 Rating_Year_2018
1 A B C
2 No Rating D E
This is a categorical value placement problem hence no existing solution worked for me on SO
I have tried the following code that gives me the right answer but I need to store this into a dataframe so that indexing cna be tackled properly going forward
df1=df.set_index(['ID','Rating_Year']).unstack()['Rating']