4 ms·
Even when not using pandas, do yourself a favour and use csv.DictReader/DictWriter, as csv format has quite some quirks. https://docs.python.org/3/library/csv.
by mkesper 12y ago
Even when not using pandas, do yourself a favour and use csv.DictReader/DictWriter, as csv format has quite some quirks.
https://docs.python.org/3/library/csv.html#csv.DictReader https://docs.python.org/3/library/csv.html#csv.DictReader
- mercurial 12y agoYes. Never use split(",") or equivalents to read or write a CSV, always use a library. Otherwise you'll get a nasty surprise next time your code encounters a line or row separator in a value.
- t1m 12y agoThe csv module has it's fair share of quirks to be aware of as well, like not supporting Unicode.
- juliangregorian 12y agoEven in Python 3?
- mkesper 12y agoIn Python3 it's completely fine, if you open the files with the correct encoding. For Python2, you've got to use UnicodeReader/Writer (and to open in binary mode): https://docs.python.org/2/library/csv.html?highlight=csv#examples https://docs.python.org/2/library/csv.html?highlight=csv#exa...
- mazelife 12y ago...which is why I usually turn to this: https://pypi.python.org/pypi/unicodecsv/0.9.4 https://pypi.python.org/pypi/unicodecsv/0.9.4 It's a "drop-in replacement for Python 2's csv module which supports unicode strings without a hassle."