我已经在线搜索了解决方案,但它在以下python脚本上无效。我在csv文件中收到你的来信。
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import codecs
import csv
cursor = db.jobs.find( {}, {'_id':1, 'locationIds':1, 'termMap.en':1 })
with codecs.open('job_test.csv', 'w', encoding='utf-8') as outfile:
fields = ['_id', 'locationIds', 'termMap.en']
write = csv.DictWriter(outfile, fieldnames=fields)
write.writeheader()
for x in cursor:
x_id = x['_id']
x_locationIds =x.get('locationIds')
x_termMap =x['termMap'].get('en')
z = {
'_id': x_id,
'locationIds':str(x_locationIds).encode('ascii', 'ignore'),
'termMap.en':str(x_termMap).encode('ascii', 'ignore') }
write.writerow(z)
输出是 _
id locationIds termMap.en
51dc52fec0d988a9547b5201 [u'00aaaaaaaaaaaaaaa5913490', u'00aaaaaaaaaaaaaaa6118158', u'00aaaaaaaaaaaaaaa5946768'] [u'abc', u'acuity', u'analyze', u'become', u'beverage']
51dc52fec0d988a9547b5202 [u'00aaaaaaaaaaaaaaa5946768'] [u'abc', u'air', u'angles', u'apples', u'banana', u'bananas', u'because', u'beings', u'birds', u'bottom']
我尝试使用许多不同的方法,但我还不能删除你的字母。请有人可以帮助我。