Pandas read_csv get rid of enclosing double quotes

csv, pandas, python

Solution

You're not going to get the list back without a bit of work

Use `literal_eval` to convert the lists

import ast

conv = dict(col_1=ast.literal_eval)
pd.read_csv(r'C:\test.csv', index_col=0, converters=conv).loc[0, 'col_1']

['a', 'b', 'c']

Problem

Here is my example: I first create dataframe and save it to file ``` import pandas as pd df = pd.DataFrame({'col_1':[['a','b','s'], 23423]}) df.to_csv(r'C:\test.csv') ``` Then `df.col_1[0]` returns `['a','b','s']` a list Later I read it from file: ``` df_1 = pd.read_csv(r'C:\test.csv', quoting = 3, quotechar = '"') ``` Now `df_1['col_1'][0]` returns `"['a' 's']"` a string. I would like to get list back. I am experimenting with different `read_csv` settings, but so far no luck

Original source