Pallawi.ds
Pallawi.ds

Reputation: 113

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. But when I am reading it in python the list of tuples is read as a string object.

Upvotes: 0

Views: 608

Answers (1)

Rohit Raj
Rohit Raj

Reputation: 339

Read csv using pandas, using following function

pandas.read_csv()

It will read list as string. To convert it into list use following function

import ast

ast.literal_eval()

Upvotes: 1

Related Questions