[英]How can I convert a pandas dataframe to an csv file without getting the UnicodeEncodeError
I am trying to export a pandas dataframe to a csv file using the to_csv() as: 我正在尝试使用to_csv()将pandas数据框导出到csv文件中,如下所示:
export_file_path=fd.asksaveasfile(filetypes=[("CSV File","*.csv"),("All Files","*.*")],defaultextension="*.csv",initialdir=fDir,initialfile="Untitled")
if export_file_path:
df.to_csv(export_file_path)
Getting this error: 收到此错误:
UnicodeEncodeError: 'charmap' codec can't encode character '\♀' in position 13: character maps to UnicodeEncodeError:'charmap'编解码器无法在位置13编码字符'\\ u2640':字符映射到
Error occurs because you are not specifying the encoding 发生错误,因为您未指定编码
Try this: 尝试这个:
df.to_csv(file_name, sep='\\t', encoding='utf-8')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.