I am having an issue expanding the values of certain cells into multiple rows. The data I'm using is from a CSV and is being imported using the following code to make a DataFrame.
import pandas as pd
import numpy as np
df = pd.read_csv("path/to/file.csv")
A small sample of the CSV data is below.
Test User,2020/09/14,Apple
Test User,2020/09/16,Apple
Test User,2020/09/23,Apple
Test User,2020/09/30,['Apple' 'Banana']
Test User,2020/10/02,Banana
Test User,2020/10/05,Apple
Test User,2020/10/07,Banana
Test User,2020/10/09,Banana
I want to take any values like the one in the 4th row and separate them. I've tried some different ways to do this, but nothing has worked so far.
Here is the df of the above data for reference.
array([['Test User', '2020/09/14', 'Apple'],
['Test User', '2020/09/16', 'Apple'],
['Test User', '2020/09/23', 'Apple'],
['Test User', '2020/09/30', "['Apple' 'Banana']"],
['Test User', '2020/10/02', 'Banana'],
['Test User', '2020/10/05', 'Apple'],
['Test User', '2020/10/07', 'Banana'],
['Test User', '2020/10/09', 'Banana']], dtype=object)
Some of the ways I have tried that didn't work
1. df = df.explode('Column name')
2. df = df.apply(pd.Series)
And different methods talked about here
To go into detail, when I use the explode command nothing happens. The cells with multiple values stay the same.
I would like to take all of the rows that have cells with multiple values in them and put them each in their own row. Here is an example of what I am trying to accomplish.
Test User,2020/09/14,Apple
Test User,2020/09/16,Apple
Test User,2020/09/23,Apple
Test User,2020/09/30,Apple
Test User,2020/09/30,Banana
Test User,2020/10/02,Banana
Test User,2020/10/05,Apple
Test User,2020/10/07,Banana
Test User,2020/10/09,Banana
Does anyone have an idea as to how I could separate those values into different rows?