2

I have a dataframe that looks like the following:

enter image description here

My goal is to expand the dataframe for each item in the list and add a index column that refers to position in the source list.

enter image description here

WHat is the best way to do this?

1 Answer 1

2

Use explode:

df = df.explode('Values')
df['index'] = df.groupby('Name').cumcount()
Sign up to request clarification or add additional context in comments.

Comments

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.