-1

I have this pandas dataframe. enter image description here

Is there a way that I could transfer (or melt??) the column names on the 1 and make it more categorical like:

              style    major  main_ingredient
chu            1.0      0.0    red meat fish
toro           1.0      0.0    red meat fish
negi_toro      1.0      0.0    red meat fish
maguro         1.0      0.0    red meat fish
tarabagani     1.0      0.0    shrimp or crab
amaebi         1.0      0.0    shrimp or crab
negi_toro_maki 0.0      0.0    red meat fish
ebi            1.0      1.0    shrimp or crab
kurumaebi      1.0      0.0    shrimp or crab
kani           1.0      0.0    shrimp or crab
Dharman
  • 30,962
  • 25
  • 85
  • 135
pancakes
  • 159
  • 1
  • 2
  • 14

1 Answers1

0

Melt should work. However it will leave you with another column with all the values from columns that are melted:

pd.melt(df, id_vars=['style', 'major'], var_name='main_ingriedient', value_name='value', ignore_index=False)
Marcin
  • 1,321
  • 7
  • 15