Skip to content Skip to sidebar Skip to footer

Match Values Of Different Dataframes

This dataframe is the principal with the original tweets. 'original_ds_.csv' id tweet --------------------------------------------- 78 'onetoon

Solution 1:

The logic is a by strange to me, but if a understand correctly, starting from these dataframes:

df1 = pd.DataFrame({'tweet': list('ABC')}, index=[78,86,72])
df2 = pd.DataFrame({'tweet': list('DEF'), 'conver_id': (78,78,12)}, index=(34,36,56))
>>>df1
   tweet
78     A
86     B
72     C

>>>df2
   tweet  conver_id
34     D         78
36     E         78
56     F         12

you can check for each element of df2['conver_id'] if it is in df1.index and map to SPANISH is True:

df2['File_Name'] = (np.vectorize({True: 'SPANISH',
                                  False: ''}.get
                                )(df2['conver_id'].isin(df1.index))
                   )

output:

   tweet  conver_id File_Name
34     D         78   SPANISH
36     E         78   SPANISH
56F12

If this is not what you want, please update your question with the expected output

Post a Comment for "Match Values Of Different Dataframes"