【发布时间】:2019-11-11 20:16:35
【问题描述】:
我有这样的 cvs 文件:
number file
1 [file1,file2]
2 [file1]
3 [file3,file4]
列file 的数据类型为list。但是当我再次读取该文件时,我得到的列file 的数据类型是str。输出是这样的:
>>> df = pd.read_csv('file.csv')
>>> for col in df:
>>> print (df[col].apply(type))
<class 'int'>
<class 'int'>
<class 'int'>
<class 'str'>
<class 'str'>
....
但是,我想将该值作为列表读取。我试过这个 [https://stackoverflow.com/a/1894296/10907221].但我不能将它应用于数据框。有人可以帮我解决这个问题吗?
谢谢
【问题讨论】:
-
您尝试stackoverflow.com/questions/1894269/…时出现什么错误?
-
@MedAli 我更新了问题,我想将 [stackoverflow.com/a/1894296/10907221] 应用于我的数据框。但是,我不知道如何
标签: python python-3.x csv dataframe