I looked at one question about 'How to convert column with a list of values into rows in Pandas DataFrame' in this link: How to convert column with list of values into rows in Pandas DataFrame. As the above question, this converted 'df' to 'df1'. In my purpose, I would like to make the contrary process that converts the df1 to df. How could I make that? Thanks.
df = pd.DataFrame({ 'var1': [['a', 'b', 'c'], ['d', 'e',], [], np.nan], 'var2': [1, 2, 3, 4] })
df
df1 = df.explode('var1')
df1
I found a similar answer using group.by(), but I prefer to return as a list in list like: