-4
我想用_替换nonunicode字符,但是这个程序尽管编译没有错误,但不能解决问题,我无法确定原因。UnicodeError替换不工作 - Python
import csv
import unicodedata
import pandas as pd
df = pd.read_csv('/Users/pabbott/Desktop/Unicode.csv', sep = ',',
index_col=False, converters={'ClinetEMail':str, 'ClientZip':str,
'LocationZip':str, 'LicenseeName': str, 'LocationState':str,
'AppointmentType':str, 'ClientCity':str, 'ClientState':str})
data = df
for row in data:
for val in row:
try:
val.encode("utf-8")
except UnicodeDecodeError:
replace(val,"_")
data.to_csv('UnicodeExport.csv', sep=',', index=False,
quoting=csv.QUOTE_NONNUMERIC)
什么是您会收到错误? – MattR
发布代码转储不是问题。 –
我没有收到任何错误,因为代码编译正确,但在新文件中,那些nonunicode字符没有被_正确替换。我想知道这是否是data.apply函数的问题? –