I have a pandas dataframe as follows
fruit_name | color
-----------+-------
apple | red
banana | yellow
orange | orange
Using this dataframe, I want to create a new dataframe as follows
name | fruit
------+-------
Ben | ['apple', 'banana', 'orange']
Alex | ['apple', 'banana', 'orange']
Jude | ['apple', 'banana', 'orange']
May | ['apple', 'banana', 'orange']
...
For this, I tried the following
new_df = pd.DataFrame(columns=['name', 'fruit']
new_df['name'] = students['name']
new_df['fruit'] = fruits['fruits_name'].to_list()
I get the following error message
ValueError: Length of values (3) does not match length of index (10)
I want my final result as follows
name | fruit
------+-------
Ben | apple
Ben | banana
Ben | orange
Alex | apple
Alex | banana
Alex | orange
...
I thought I would use the explode function once I have a column of lists. But I am stuck getting the dataframe with the column of lists.