Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Column to rows
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to assign a value to pandas dataframe column rows based on a condition klllmmm 0 850 Sep-08-2022, 06:32 AM
Last Post: klllmmm
  The code I have written removes the desired number of rows, but wrong rows Jdesi1983 0 1,636 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983
  Pandas DataFrame combine rows by column value, where Date Rows are NULL rhat398 0 2,125 May-04-2021, 10:51 PM
Last Post: rhat398
  Indexing [::-1] to Reverse ALL 2D Array Rows, ALL 3D, 4D Array Columns & Rows Python Jeremy7 8 7,155 Mar-02-2021, 01:54 AM
Last Post: Jeremy7
  How to filter out Column data From Multiple rows data? firaki12345 10 5,148 Feb-06-2021, 04:54 AM
Last Post: buran
  how to combine rows to a column base on ids zhujp98 0 1,502 Nov-03-2020, 04:10 PM
Last Post: zhujp98
  How to generate rows based on values in a column to fill missing values codesmatter 1 2,140 Oct-31-2020, 12:05 AM
Last Post: Larz60+
  How to diff pandas rows and modify column value Mekala 1 1,709 Sep-18-2020, 12:38 PM
Last Post: Mekala
  How to calculate unique rows column sum and percentage SriRajesh 4 3,474 Feb-12-2020, 02:21 PM
Last Post: SriRajesh
  Do Calculation between Rows based on Column values - Pandas Dataframe ahmedwaqas92 0 2,156 Jan-28-2020, 07:06 AM
Last Post: ahmedwaqas92

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020