Answer the question
In order to leave comments, you need to log in
How to solve the problem of Cyrillic characters in csv?
There is data in mongodb from which I collect csv file.
CSV is collected, but Russian characters are there in the form of krakozyabr.
The csv creation code is the following:
from pymongo import MongoClient
import csv
filename = 'products.csv'
with open(filename, "w", encoding="utf-8", newline="") as file:
columns = ["url", "name", "price", "manufacturer", "country"]
writer = csv.DictWriter(file, fieldnames=columns)
client = MongoClient('localhost', 27017)
db = client.site
collection = db.products
rows = collection.find()
for row in rows:
del row['_id']
if row['manufacturer'] == "":
row['manufacturer'] = "-"
if row['country'] == "":
row['country'] = "-"
writer.writerow(row)
print(row)
Answer the question
In order to leave comments, you need to log in
In encoding. Office only wants 1251. With others, you have to manually set the file. You feed him utf8
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question