Transcoding text in a set of files

@JM64 one thing you could do is employ Python and ChatGPT to create a small Python code to do what you want and put this into a KNIME workflow to handle the rest of your tasks.

The code would look something like this:

import knime.scripting.io as knio
import numpy as np
import pandas as pd

# Step 1: Import the file
v_import_file = knio.flow_variables["File path"]
df = pd.read_csv(v_import_file, sep='\t', dtype=str, header=None)

# Step 2 & 3: Scan each column and replace strings
for column in df.columns:
    df[column] = df[column].apply(lambda x: '100' + x[3:] if isinstance(x, str) and x.startswith('000') and len(x) == 18 else x)

# Step 4: Save the modified DataFrame (optional)
v_export_file = knio.flow_variables["result_file"]
df.to_csv(v_export_file, sep='\t', index=False, header=False)

knio.output_tables[0] = knio.Table.from_pandas(df)
4 Likes