Read data from CSV file and transform from string to correct data-type, including a list-of-integer column

前端 未结 7 1509
难免孤独
难免孤独 2020-11-28 09:44

When I read data back in from a CSV file, every cell is interpreted as a string.

  • How can I automatically convert the data I read in into the correct type?
7条回答
  •  时光取名叫无心
    2020-11-28 10:19

    An alternative (although it seems a bit extreme) in lieu of using ast.literal_eval is the pyparsing module available on PyPi - and see if the http://pyparsing.wikispaces.com/file/view/parsePythonValue.py code sample is either appropriate for what you require, or can be easily adapted.

提交回复
热议问题