consider the df
df = pd.DataFrame(dict(A=[-1, 0, 1, np.nan, 2, np.nan, 3, 4]))
I can drop NA like this
df.dropna()

but how do I do it within the query method
df.query('A is not null')
doesn't work... what does?
Idea #2: what's distinctive about NaNs is that they're not equal to themselves:
In [22]: df.query("A == A")
Out[22]: 
     A
0 -1.0
1  0.0
2  1.0
4  2.0
6  3.0
7  4.0
(The original idea #1 was to use df.query("A.notnull()"), but that only worked because numexpr wasn't installed in that environment, which limits the usefulness of query in the first place.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With