【发布时间】:2022-07-19 05:17:50
【问题描述】:
在研究涉及按位 AND 运算符的主题时,我偶然发现了以下事件。
访问 Pandas DataFrame 的 Series 并执行相同的条件检查,返回的结果不同。
- 第 95 行和第 96 行的幕后发生了什么?
- 为什么两个数据帧的结果不同?
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]:
标签: python pandas dataframe bitwise-operators