N
Something like that. If you only have these columns, you'll have an extra check. any I don't need it, especially since I clearly didn't write it properly.import pandas as pd
df = pd.DataFrame({'int': [1, 2, 3], 'obj1': ['yes', 'no', 'yes'], 'obj2': ['no', 'yes', 'no'], 'obj3': ['n', 'y', 'n']})
obj_columns = df.columns[df.dtypes == 'object'].to_list()
for col in obj_columns:
if any(df[col].str.contains(x).any() for x in ('yes','no')):
df[col] = df[col].map({'yes': 1, 'no': 0})
Out: int obj1 obj2 obj3
0 1 1 0 n
1 2 0 1 y
2 3 1 0 n