📜  如何将列表数据类型的列字符串更改为列表 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:21.356000             🧑  作者: Mango

代码示例1
from ast import literal_eval
import pandas as pd

# convert the column during import
df = pd.read_csv('test.csv', converters={'col1': literal_eval})

# display(df)
                                col1
0                       [1.23, 2.34]
1  [KB4523205, KB4519569, KB4503308]

# check type
print(type(df.iloc[0, 0]))
list

print(type(df.iloc[1, 0]))
list