I imported a CSV using Pandas and one column was read in with string entries. Examining the entries for this Series (column), I see that they should actually be lists. For example:
df['A'] = pd.Series(['["entry11"]', '["entry21","entry22"]', '["entry31","entry32"]'])
I would like to extract the list elements from the strings. So far, I've tried the following chain:
df['A'] = df['A'].replace("'",'',regex=True).
replace('\[','',regex=True).
replace('\]','',regex=True).
str.split(",")
(all on one line, of course).
and this gives me back my desired list elements in one column.
- ['"entry11"']
- ['"entry21", "entry22"']
- ['"entry31", "entry32"']
My question: Is there a more efficient way of doing this? This seems like a lot of strain for something that should be a little easier.