Skip to content Skip to sidebar Skip to footer

Match Values Of Different Columns And Dataframes

Check if value from one dataframe exists in another dataframe df_threads = pd.DataFrame({'conv_id': ['12', '15', '14', '23'], 'tweets': ['Nice', 'Test', 'Hi', 'Yes']}) df_orig = p

Solution 1:

Use np.where and df.where:

df_threads['File'] = np.where(df_threads['conv_id'].isin(df_orig['id']),
                              'Spanish', 'Portuguese')
>>>df_threads
  conv_id    tweets        File
0      12      Nice     Spanish
1      15      Test     Spanish
2      14        Hi  Portuguese
3      23       Yes  Portuguese

Note: check your input data and your outcome, they not match.

Post a Comment for "Match Values Of Different Columns And Dataframes"