Expand DataFrame based on list and add index

Viewed 42

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 Answers

Use explode:

df = df.explode('Values')
df['index'] = df.groupby('Name').cumcount()
Related