xxxxxxxxxx
new_df = df[~df["col"].str.contains(word)]
xxxxxxxxxx
# simply use the invert operator '~' with 'str.contains'
new_df = df[~df["col"].str.contains(word)]
xxxxxxxxxx
import pandas as pd
# Sample DataFrame
df = pd.DataFrame({'col1': [1, 2, 3], 'col2': [4, 5, 6], 'col3': [7, 8, 9]})
# Check if any column name contains a specific string
search_string = 'col'
has_string = any(search_string in column_name for column_name in df.columns)
print(has_string)