Search code examples
pythonpandascsvdelimiterseparator

How do I change the delimiter used in CSV file?


UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 2219: character maps to <undefined

I would appreciate your help


Solution

  • From CSV Examples:

    Since open() is used to open a CSV file for reading, the file will by default be decoded into unicode using the system default encoding (see locale.getpreferredencoding()). To decode a file using a different encoding, use the encoding argument of open:

    import csv
    with open('some.csv', newline='', encoding='utf-8') as f:
        reader = csv.reader(f)
        for row in reader:
            print(row)
    

    The same applies to writing in something other than the system default encoding: specify the encoding argument when opening the output file.