Answer the question
In order to leave comments, you need to log in
csv file encoding. How to change?
There is a csv file in windows-1251 encoding. In Python, I use the pandas library to work with this file. There are problems when deleting Cyrillic characters. How to change encoding using Python to utf-8?
Answer the question
In order to leave comments, you need to log in
In [1]: with open('/tmp/1', 'w+', encoding='cp1251') as f: f.write('qwertyйцукен')
In [2]: cat /tmp/1
qwerty������
In [3]: with open('/tmp/1', 'r', encoding='cp1251') as f: print(f.read())
qwertyйцукен
In [4]: with open('/tmp/1', 'r', encoding='cp1251') as f:
...: with open('/tmp/2', 'w+', encoding='utf-8') as o: o.write(str(f.read()))
...:
In [5]: cat /tmp/2
qwertyйцукен
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question