0

I'm trying to parse a csv downloaded file from my bank account. The file gets opened with:

with open('umsatz.csv', 'r', encoding="utf-8") as csv_file:

When trying to simply print the various entries I got the following error:

  File "C:\Users\joajo\AppData\Local\Programs\Python\Python39\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\ufffd' in position 13: character maps to <undefined>

Opening in notepad++ the problematic texts looks like:

LOHN-/GEHALTS�BERTRAGFREMDSPESE
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
  • Can you share your file somewhere (i.e. google drive)? – Alderven Dec 06 '20 at 13:13
  • 2
    Does this answer your question? [Why I'm getting "UnicodeEncodeError: 'charmap' codec can't encode character '\u25b2' in position 84811: character maps to " error?](https://stackoverflow.com/questions/62656579/why-im-getting-unicodeencodeerror-charmap-codec-cant-encode-character-u2) – Tomerikoo Dec 06 '20 at 13:19
  • Can your share your ```sys.stdout.encoding``` output? You can do so by ```import sys``` first. – Henry Tjhia Dec 06 '20 at 13:21

1 Answers1

1

Just open in 'rb' format. Here the code:

with open('umsatz.csv', 'rb') as csv_file:
     data = csv_file.read().decode('utf-8')
shekhar chander
  • 600
  • 8
  • 14