How can I rearrange a dataframe so that values of a particular column that are repeated appear only once and the related data is transposed to columns?
Suppose I have a dataframe given by:
df1 = DataFrame(NAME = ["A1","A1","A1","A2","A2","A3","A3"], CAT = ["FIN","NF","INF","UTL","GT","CP","MP"])
I would like to reshape df1
so that it appears like df2, i.e. entries in the column NAME are not repeated.
df2= DataFrame(NAME = ["A1","A2","A3"], CAT1=["FIN","NF","INF"],CAT2=["UTL","GT",""],CAT3=["CP","MP",""])
I have tried to use groupby
function, but no luck. How can I rearrange a dataframe?