I am looking for a way to convert my dataframe columns as rows. Following is my example dataframe:
mylist= [['xx'], [None, 'yy'], ['xx', None], ['xx',None],['xx','yy']]
pd.DataFrame(mylist,index=['A','B','C','D','E'],columns=['Col1','Col2'])
Input DataFrame:
-------------------
Ind | Col1 | Col2 |
-------------------
A | xx | None |
B | None | yy |
C | xx | None |
D | xx | None |
E | xx | yy |
-------------------
I want to split my columns as separate rows in the dataframe. Below is how my desired output looks like. Can anyone suggest how to acheive the following.
Desired dataframe:
------------------------
Ind | Values | Columns |
------------------------
A | xx | Col1 |
B | yy | Col2 |
C | xx | Col1 |
D | xx | Col1 |
E | xx | Col1 |
E | xx | Col2 |
------------------------
Thanks,
Rtut