0

I've been trying to use reverse explode from here: How to implode(reverse of pandas explode) based on a column

But I have a little bit different df.

I have df looking like this:

enter image description here

I need to 'reverse explode' it, but I couldn't find any option to groupby by index. Is there any option to do that?

To be precise, I need all columns to remain, but all '1' should be combined in a row. I merged dummy df with main df, but can not figure out what to do next.

rest_cuisine_style = pd.concat([rest_cuisine_style, cuisine_dummies], axis=1)
I'mahdi
  • 23,382
  • 5
  • 22
  • 30

1 Answers1

0

Does this work?

rest_cuisine_style = rest_cuisine_style.idxmax(axis=1)
anarchy
  • 3,709
  • 2
  • 16
  • 48