-1

I have the data in the Pandas DataFrame in the below format: enter image description here

Now I want to convert it into the below format with pandas: enter image description here

Can someone please help.

The data should be for all the Referrer Type with the count and Device Type will contain the Column headers.

pmacfarlane
  • 3,057
  • 1
  • 7
  • 24

1 Answers1

0

Use pd.melt, passing the columns you want to keep to id_vars:

pd.melt(df, id_vars=["Brand", "Referrer Type"])
CarlosGDCJ
  • 424
  • 1
  • 8