Python Pandas - Check If Partial String In Column Exists In Other Column
Take a sample dataset: df = pd.DataFrame([['Mexico', 'Chile'], ['Nicaragua', 'Nica'], ['Colombia', 'Mex']], columns = ['col1', 'col2']) The dataframe looks like this: I have two c
Solution 1:
This looks like an expensive operation. You can try:
df['col2'].apply(lambda x: 'Yes' if df['col1'].str.contains(x).any() else 'No')
Output:
0 No
1 Yes
2 Yes
Name: col2, dtype: object
Post a Comment for "Python Pandas - Check If Partial String In Column Exists In Other Column"