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.

2
  • stackoverflow.com/questions/12680754/… Commented Jan 8, 2022 at 11:57
  • Will check this out. Thank You Commented Jan 8, 2022 at 11:59

1 Answer 1

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")
Sign up to request clarification or add additional context in comments.

2 Comments

Perfect! Thank you.
If this solves your issue could you please validate the answer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.