0

I have DataFrame like this:

>>> data = {'Section':['150/12','140/15'], '2m':[4.1, 5.2], '3m':[5.1, 6.2], 'W':[100,125], 'D':[300,400]}
>>> df = pd.DataFrame(data)
>>> df
  Section   2m   3m    W    D
0  150/12  4.1  5.1  100  300
1  140/15  5.2  6.2  125  400

I want the new DataFrame like this:

   2m   4.1 150/12  100 300
   2m   5.2 140/15  125 400
   3m   5.1 150/12  100 300
   3m   6.2 140/15  125 400
Henry Ecker
  • 31,792
  • 14
  • 29
  • 50
warem
  • 1,349
  • 1
  • 13
  • 21
  • 1
    [DataFrame.melt](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.melt.html) -> `new_df = df.melt(id_vars=['Section', 'W', 'D'])` – Henry Ecker Dec 15 '21 at 23:32

0 Answers0