In Pandas, Using Isin To Match Dataframe To Other Dataframe
I have 2 dataframes: local_PC_user_filer_OpCode_sum: client_op clienthostid eventSum feeling usersidid 0 5030 1 1 Happy 5 1 5030
Solution 1:
You can use join
:
cols = ['usersidid', 'clienthostid']
a = local_PC_user_filer_OpCode_sum.set_index(cols)
print (df_old_enough_users.join(a, on=cols, lsuffix='_x')[local_PC_user_filer_OpCode_sum.columns].reset_index(drop=True))
client_op clienthostid eventSum filerid feeling usersidid
05030111 Happy 515030121 Mad 5
isin
solution does not work, because columns
and index
matching is necessary too in both DataFrames
.
Solution 2:
If you are interested in modifying @jezrael's answer, this might give you a cleaner answer.
df = pd.merge(local_PC_user_filer_OpCode_sum,
df_old_enough_users[['usersidid','clienthostid']],
on=['usersidid','clienthostid'],
how="right")["client_op", "clienthostid", "eventSum", "filerid", "timestamp", "usersidid"]
df will have the exact columns from your original local_PC_user_filer_OpCode_sum
dataframe, and the rows returned will only be on the right table that you used as the filter.
Post a Comment for "In Pandas, Using Isin To Match Dataframe To Other Dataframe"