简体   繁体   English

如何将 csv 列读取为列表而不是 python 中的字符串?

[英]How to read a csv column as list and not as a string in python?

I have a CSV file in which one column is a list of tuples.我有一个 CSV 文件,其中一列是元组列表。 But when I am reading it in python the list of tuples is read as a string object.但是当我在 python 中读取它时,元组列表被读取为字符串 object。

Read csv using pandas, using following function使用 pandas 读取 csv,使用以下 function

pandas.read_csv()

It will read list as string.它将列表读取为字符串。 To convert it into list use following function要将其转换为列表,请使用 function

import ast

ast.literal_eval()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM