Reputation: 1133
I have a dataframe that looks like the following:
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.
WHat is the best way to do this?
Upvotes: 2
Views: 162
Reputation: 93161
Use explode
:
df = df.explode('Values')
df['index'] = df.groupby('Name').cumcount()
Upvotes: 2