Python Forum
Column to rows - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Column to rows (/thread-29164.html)



Column to rows - kmrashish1985 - Aug-20-2020

I have a dataframe like shown below -

Col X Col 1 Col 2 Col 3 Col 4 Col 5 Col 6 Col 7 Col 8 Col 9 Col 10
AA A 1 1 1 1 1 1 1 1 1
BB B 3 3 3 3 3 3 3 3 3

There may be no limitation on number of columns. Col2 - Col 10 are just for example .. There could be may such columns.

What i need is a dataframe using Panda which looks like below -

Col X Col 1 New Column New Column Value
AA A Col2 1
AA A Col3 1
AA A Col4 1
AA A Col5 1
AA A Col6 1
AA A Col7 1
AA A Col8 1
AA A Col9 1
AA A Col10 1
BB B Col2 3
BB B Col3 3
BB B Col4 3
BB B Col5 3
BB B Col6 3
BB B Col7 3
BB B Col8 3