when I write a list in pandas when I read it, its dtype is string and not array, is there any way to write a column of list in such a way that be again array type when we read it?
Here is what I mean:
d=[['d',['A','B','C']],['p',['F','G']]]
df=pd.DataFrame(d)
df.to_csv('file.csv')
when I run the following code,
pd.read_csv('file.csv')['1'].values[0]
the output is:
"['A', 'B', 'C']"
but I want this:
['A', 'B', 'C']
CodePudding user response:
one solution would be to run it through
type(df1["1"][0])
output: