python - Filtering data in pandas -
i working pandas 0.13.0
i have data frame(a) 2.5 million records
i want exclude hundreds of records applying 2 conditions simoultaneusly: records fulfill 2 conditions @ same time.
i want see how many records exclude when applying both conditions:
len(a) 2523250 b=a[(a.cond1=='120.a') & (a.cond2==2012)] len(b) 6010
but when apply conditions obtain final dataframe:
c=a[(a.cond1!='120.a') & (a.cond2!=2012)] len(c) 2214968
in second case '&' working , 'or' doing wrong?
review de morgan's laws. logical negation of &
not switching ==
!=
, must swap &
|
, because want rows either cond1 != '120.a'
or cond2 != 2012
, i.e., want exclude row if 1 of !=
conditions true because makes original &
statement false
.
@edchum's comment above equivalent to
c=a[(a.cond1!='120.a') | (a.cond2!=2012)]
Comments
Post a Comment