KNIME and UTF-8 characters with CSV between Python nodes with Pandas and Arrow
import knime.scripting.io as knio
import pyarrow as pa
import pyarrow.csv as csv
import pandas as pd
var_import_csv_file = knio.flow_variables['v_path_csv_file']
# import CSV file with Arrow
df_arrow = csv.read_csv(var_import_csv_file
, read_options = csv.ReadOptions(encoding='utf8')
, parse_options= csv.ParseOptions(delimiter='|', quote_char = '"')
)
var_csv_from_arrow_path = knio.flow_variables['context.workflow.data-path'] + "from_arrow_csv_file.csv"
knio.flow_variables['var_csv_from_arrow_path']= var_csv_from_arrow_path
csv.write_csv(df_arrow, var_csv_from_arrow_path)
# import CSV file with Pandas ------------------------------------------------
df_pandas = pd.read_csv(var_import_csv_file, sep="|", encoding = "utf8")
var_csv_from_pandas_path = knio.flow_variables['context.workflow.data-path'] + "from_pandas_csv_file.csv"
knio.flow_variables['var_csv_from_pandas_path']= var_csv_from_pandas_path
# , compression='gzip'
df_pandas.to_csv(var_csv_from_pandas_path, sep='|', encoding='utf-8')
knio.output_tables[0] = knio.Table.from_pyarrow(df_arrow)
knio.output_tables[1] = knio.Table.from_pandas(df_pandas)
To use this workflow in KNIME, download it from the below URL and open it in KNIME:
Download WorkflowDeploy, schedule, execute, and monitor your KNIME workflows locally, in the cloud or on-premises – with our brand new NodePit Runner.
Try NodePit Runner!Do you have feedback, questions, comments about NodePit, want to support this platform, or want your own nodes or workflows listed here as well? Do you think, the search results could be improved or something is missing? Then please get in touch! Alternatively, you can send us an email to mail@nodepit.com.
Please note that this is only about NodePit. We do not provide general support for KNIME — please use the KNIME forums instead.