python - doing joins in filter criteria in pandas -
if have 2 dataframes like:
df1: | | b | 0 | 0 | 0 | 1 | 0 | 1 | 2 | 1 | 1 | df2: | c | d | 0 | 0 | 1 | 1 | 1 | 1 | 2 | 2 | 1 |
how select rows df2
df1[df2['c']]['b'] != 0
. in other words, rows df2 it's value in column c
index used check value in df1 column b
not equal 0.
so 1 other way @ it. select columns df2
column c
foreign key df1
, , don't want value in column b
equal 0.
i think should trick. let me know if need else.
df1['index1'] = df1.index df = pandas.merge(df1, df2, how='left', left_on=['index1'], right_on=['c']) df = df[df.b != 0]
Comments
Post a Comment