While working on a topic involving the bitwise AND operator I stumbled over the below occurrence.
Accessing the Series of the Pandas DataFrames and performing the same conditional check, the returned result differs.
- What is happening under the hood in line 95 and 96?
- And why do the outcomes differ for the two dataframes?
In [91]: df = pd.DataFrame({"h": [5300, 5420, 5490], "l": [5150, 5270, 5270]})
In [92]: df
Out[92]:
h l
0 5300 5150
1 5420 5270
2 5490 5270
In [93]: df2 = pd.DataFrame({"h": [5300.1, 5420.1, 5490.1], "l": [5150.1, 5270.1, 5270.1]})
In [94]: df2
Out[94]:
h l
0 5300.1 5150.1
1 5420.1 5270.1
2 5490.1 5270.1
In [95]: df["h"].notna() & df["l"]
Out[95]:
0 False
1 False
2 False
dtype: bool
In [96]: df2["h"].notna() & df2["l"]
Out[96]:
0 True
1 True
2 True
dtype: bool
In [97]: