Skip to content
Advertisement

How to transform a .csv string list representation to list?

Suppose a .csv file which looks like this:

  • title: is the name of the column
  • and [senior innovation manager] is the first row.

Note: both strings (title and row) look exactly as written here.

JavaScript

The idea is to convert this list string representation to an actual python list:

JavaScript

However when tried the above code the next error arises:

JavaScript

What’s the nature of this error?

Is it possible to convert this list string representation to an actual python list?

Advertisement

Answer

I don’t see any advantage to treating this as a CSV file or using pandas. You could simply read the second line of the file and strip the unwanted stuff out. You can do that by grabbing a slice from the second character to one before the end. In python list syntax, that’s 1:-1.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement