0

Have got a df which looks like this:

Item    Match
a       bb,cc
b       dd,ee

want to expland the column 'Match' as below:

Item    Match
a       bb
a       cc
b       dd
b       ee

tried df.explode('Match') but didn't worked for me. Kindly share your ideas.

user12345
  • 499
  • 1
  • 5
  • 21

1 Answers1

4

I think this will solve your issue:

import pandas as pd
df = pd.DataFrame({"Item": ["a", "b"], "Match": ["bb,cc", "dd,ee"]})
df["Match"] = df["Match"].str.split(",")
df.explode("Match")
Antoine
  • 577
  • 4
  • 17