I am trying to export a pandas dataframe to a csv file using the to_csv() as:
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
Error occurs because you are not specifying the encoding
Try this:
df.to_csv(file_name, sep='\\t', encoding='utf-8')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.