我有一个数据框,其中包含一个具有列表的列。当我将数据框写入文件然后重新打开它时,我最终将列表转换为字符串。有没有办法安全地读取/写入以列表为成员的数据帧?
df1 = DataFrame({'a':[['john quincy', 'tom jones', 'jerry rice'],['bob smith','sally ride','little wayne'],['seven','eight','nine'],['ten','eleven','twelve']],'b':[9,2,4,5], 'c': [7,3,0,9]})
df1.to_csv('temp.csv')
df2 = read_csv('temp.csv')
#note how the list (df1) has been converted to a string (df2)
df1['a'][0]
['john quincy', 'tom jones', 'jerry rice']
df2['a'][0]
"['john quincy', 'tom jones', 'jerry rice']"