Convert dataframe column with values in the form of a list into a string in the same column

Viewed 44

This is how the pandas dataframe looks like:

A B C D
A1 ['Bb1'] [54] [84.0]
A2 ['Bb2'] [63] [nan]

Following is how the dataframe should be:

A B C D
A1 Bb1 54 84.0
A2 Bb2 63 nan
1 Answers

As of pandas 1.3.0:

df.explode(['B', 'C', 'D'])

Or before:

df.set_index('A').apply(pd.Series.explode).reset_index()
Related