-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
  • 26,923
  • 21
  • 73
  • 125
pancakes
  • 165
  • 1
  • 12

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,177
  • 6
  • 12