Search code examples
pandasdataframemergeappendmultiple-columns

How to concatenate two columns so that one comes below the other in pandas dataframe?


  Col-1    Col-2
0 Erin     Tanya
1 Cathy    Tom
2 Ross     Wes

This is my dataset

I need the result to look like this:

  New_column
0 Erin
1 Cathy
2 Ross
3 Tanya
4 Tom
5 Wes

I tried using .map, append, concat and .ravel but no luck. Any help would be appreciated :)


Solution

  • Use DataFrame.melt:

    df1 = df[['Col-1','Col-2']].melt(value_name='New_column')[['New_column']]
    
    print (df1)
      New_column
    0       Erin
    1      Cathy
    2       Ross
    3      Tanya
    4        Tom
    5        Wes