1

After using str.extractall(), I have a multi-level dataframe that looks like this:

id  match  Names
1   0      Rob Corddry
    1      Craig Robinson
    2      Clark Duke
...
1   23     Kisha Sierra
2   0      Anne Hathaway
    1      Julie Andrews
...

I want a series or dictionary that looks like this with all the names in a single row that share the same "id":

id  Names
1   Rob Corddry, Craig Robinson, Clark Duke ... Kisha Sierra     
2   Anne Hathaway, Julie Andrews ...

I want to merge this series/dict back into the dataframe I extracted it from on the index id.

1 Answer 1

2

You can using groupby agg + join

df.groupby(level=0).agg(','.join)
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect. Thank you @Wen-Ben

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.