UnicodeEncodeError: 'charmap' codec can't encode characters

My Python Script node has the UnicodeEncodeError after I use the CSV Reader to read a Chinese-content CSV with “UTF-8”. The output file of the CSV Reader is fine (which encode Chinese characters sucessfully). However, the Python Script cannot encode the text field in Chinese.

I even put below code in Python Script node:
import pandas as pd
data = pd.read_csv(‘…/Data/202007-08sample20%.csv’,encoding = ‘utf-8’)

however, when I executed
print (data.text) #Text is a column in the csv file, it contains Chinese in String. UnicodeEncodeError: ‘charmap’ codec can’t encode characters comes up.

probably best to provide a sample so the forum can help


@wuyeehow welcome to the KNIME forum. I tried it with this files and settings and imported and exported CSV files from within the Python node with Pandas and Arrow and it seems to work. Also from an earlier workflow I used Parquet and SQLite which also seem to work fine.

Maybe you check that out and see if you can adapt your workflows.

1 Like