Icon

kn_​forum_​39612_​python_​edifact_​parse

Try to import EDIFACT files with Python package "pydifact"

Try to import EDIFACT files with Python package "pydifact"

# import the KNIME moduleimport knime_io as knioimport pandas as pdimport pyarrow as pqfrom pydifact.segmentcollection import Interchangev_import_file = knio.flow_variables['File path']interchange = Interchange.from_file(v_import_file)segment_tag_list = []content_list = []for message in interchange.get_messages(): for segment in message.segments: segment_tag_list.append(segment.tag) content_list.append(segment.elements)df = pd.DataFrame(list(zip(segment_tag_list , content_list)), columns =['segment_tag', 'content']) df['segment_tag'] = df['segment_tag'].astype("string")df['content'] = df['content'].astype("string")knio.output_tables[0] = knio.write_table(df) Try to import EDIFACT files with Python package "pydifact"in the folder /script/ theer is a Jupyter notebook to try the code: kn_forum_39612_python_edifact_parse.ipynb searchCommon_file.xlsxsee filter optionsExtract path informationsnew file namewith extensionv_new_file_name"file.separator" (STRING: \)create pathconda.environmentpy39_knimePython codeSTARTwrite ExcelSTOPfile_nameSTOPPython codefile_nameSTART List Files/Folders Path to URI URL to File Path Java Snippet(simple) Extract SystemProperties Table Columnto Variable String to Path Conda EnvironmentPropagation Python Script(Labs) Table Row ToVariable Loop Start Excel Writer Variable Loop End ConstantValue Column Loop End Python Script(Labs) ConstantValue Column Table Row ToVariable Loop Start # import the KNIME moduleimport knime_io as knioimport pandas as pdimport pyarrow as pqfrom pydifact.segmentcollection import Interchangev_import_file = knio.flow_variables['File path']interchange = Interchange.from_file(v_import_file)segment_tag_list = []content_list = []for message in interchange.get_messages(): for segment in message.segments: segment_tag_list.append(segment.tag) content_list.append(segment.elements)df = pd.DataFrame(list(zip(segment_tag_list , content_list)), columns =['segment_tag', 'content']) df['segment_tag'] = df['segment_tag'].astype("string")df['content'] = df['content'].astype("string")knio.output_tables[0] = knio.write_table(df) Try to import EDIFACT files with Python package "pydifact"in the folder /script/ theer is a Jupyter notebook to try the code: kn_forum_39612_python_edifact_parse.ipynb searchCommon_file.xlsxsee filter optionsExtract path informationsnew file namewith extensionv_new_file_name"file.separator" (STRING: \)create pathconda.environmentpy39_knimePython codeSTARTwrite ExcelSTOPfile_nameSTOPPython codefile_nameSTARTList Files/Folders Path to URI URL to File Path Java Snippet(simple) Extract SystemProperties Table Columnto Variable String to Path Conda EnvironmentPropagation Python Script(Labs) Table Row ToVariable Loop Start Excel Writer Variable Loop End ConstantValue Column Loop End Python Script(Labs) ConstantValue Column Table Row ToVariable Loop Start

Nodes

Extensions

Links