0

I have a csv with the column 'c' with values like:

set()
['a', 'b', 'a', 'a', 'b']
{'a', 'b', 'd', 'e'}

I am currently reading the csv with and would like to pass the method into the converter.

pd.read_csv('tmp.csv', sep';', encoding='utf-8', converters={'c': pd.eval})

pd.eval is sadly not working. Does anyone know a solution/already implemented method for this?

  • 2
    You **really** shouldn't be storing this as text. But `eval` should work (or more safe if you don't trust the source, `import ast` and use `ast.literal_eval`). But you should probably move your format to something that can actaully deal with arbitary python objects, so not a text-based CSV format, but maybe `pickle`. – juanpa.arrivillaga Feb 09 '22 at 17:33

0 Answers0