How to created new rows on pandas using data from existing colum?

  dataframe, pandas, python, python-3.x

I want to get the data from some columns and create new rows with it. In my case, the same product was can be sold many times, and each time it was sold again, my df created a new column, I’d like to take the data from those columns and put them in rows, keeping the same "prevenda" field.

It looks like this:

ID Product Value Produc01 Value01
0 A 1,20 a 2
1 A 3,30 b 9
2 B 5,50 c 4
3 B 4,30 d 2
4 B 450 Nan Nan
5 B 6,30 Nan Nan
6 C 9,30 Nan Nan

and I’d to look like this:

ID Product Value 
 0      A    1,20   
 1      A    3,30   
 2      B    5,50   
 3      B    4,30  
 4      B    450    
 5      B    6,30   
 6      C    9,30   
 0      a    2
 1      b    9
 2      c    4
 3      d    2

Keeping the same ID. but putting the values from the coloumns in others rows.

Source: Python-3x Questions

LEAVE A COMMENT