Icon

kn_​example_​python_​filter_​columns

use Python to drop columns with specific names

use Python to drop columns with specific names

import pandas# https://stackoverflow.com/questions/21285380/find-column-whose-name-contains-a-specific-string v_colums_to_filter = [col for col in input_table.columns if '<span' in col]# https://thispointer.com/python-pandas-drop-columns-in-dataframe-by-label-names-or-by-index-positions/input_table = input_table.drop(v_colums_to_filter , axis='columns')output_table = input_table.copy() use Python to drop columns with specific nameshttps://forum.knime.com/t/i-am-trying-to-filter-a-database-table-column-via-python-script-but-when-i-am-trying-to-execute-it-i-am-getting-the-error-output-table-input-table-copy-syntaxerror-invalid-syntax/18797 import knime.scripting.io as knioimport pandas# https://stackoverflow.com/questions/21285380/find-column-whose-name-contains-a-specific-stringinput_table = knio.input_tables[0].to_pandas() v_colums_to_filter = [col for col in input_table.columns if '<span' in col]# export as Flow Variableknio.flow_variables['colums_to_filter'] = v_colums_to_filter# https://thispointer.com/python-pandas-drop-columns-in-dataframe-by-label-names-or-by-index-positions/input_table = input_table.drop(v_colums_to_filter , axis='columns')knio.output_tables[0] = knio.Table.from_pandas(input_table.copy()) drop column based on part of stringdrop column based on part of stringfiler based onknio.flow_variables['colums_to_filter'] Table Creator Python Script (1⇒1)(deprecated) Python Script Column Filter import pandas# https://stackoverflow.com/questions/21285380/find-column-whose-name-contains-a-specific-string v_colums_to_filter = [col for col in input_table.columns if '<span' in col]# https://thispointer.com/python-pandas-drop-columns-in-dataframe-by-label-names-or-by-index-positions/input_table = input_table.drop(v_colums_to_filter , axis='columns')output_table = input_table.copy() use Python to drop columns with specific nameshttps://forum.knime.com/t/i-am-trying-to-filter-a-database-table-column-via-python-script-but-when-i-am-trying-to-execute-it-i-am-getting-the-error-output-table-input-table-copy-syntaxerror-invalid-syntax/18797 import knime.scripting.io as knioimport pandas# https://stackoverflow.com/questions/21285380/find-column-whose-name-contains-a-specific-stringinput_table = knio.input_tables[0].to_pandas() v_colums_to_filter = [col for col in input_table.columns if '<span' in col]# export as Flow Variableknio.flow_variables['colums_to_filter'] = v_colums_to_filter# https://thispointer.com/python-pandas-drop-columns-in-dataframe-by-label-names-or-by-index-positions/input_table = input_table.drop(v_colums_to_filter , axis='columns')knio.output_tables[0] = knio.Table.from_pandas(input_table.copy()) drop column based on part of stringdrop column based on part of stringfiler based onknio.flow_variables['colums_to_filter']Table Creator Python Script (1⇒1)(deprecated) Python Script Column Filter

Nodes

Extensions

Links