I have a Panda dataframe that contains two columns, as well as a default index. The first columns is the intended 'Column Name' and the second column the required value for that column.
name returnattribute
0 Customer Name Customer One Name
1 Customer Code CGLOSPA
2 Customer Name Customer Two Name
3 Customer Code COTHABA
4 Customer Name Customer Three Name
5 Customer Code CGLOADS
6 Customer Name Customer Four Name
7 Customer Code CAPRCANBRA
8 Customer Name Customer Five Name
9 Customer Code COTHAMO
I would like to povit this so that instead of 10 rows, I have 5 rows with two columns ('Customer Name' and 'Customer Code'). The hoped for result is as below:
Customer Code Customer Name
0 CGLOSPA Customer One Name
1 COTHABA Customer Two Name
2 CGLOADS Customer Three Name
3 CAPRCANBRA Customer Four Name
4 COTHAMO Customer Five Name
I have tried to use the pandas pivot function:
df.pivot(columns='name', values='returnattribute')
But this results in ten rows still with alternate blanks:
Customer Code Customer Name
0 NaN Customer One Name
1 CGLOSPA NaN
2 NaN Customer Two Name
3 COTHABA NaN
4 NaN Customer Three Name
5 CGLOADS NaN
6 NaN Customer Four Name
7 CAPRCANBRA NaN
8 NaN Customer Five Name
9 COTHAMO NaN
How to I pivot the dataframe to get just 5 rows of two columns?