[英]strange behavior: apparently a numpy nan in a pandas dataframe showing up as dtype('float64')
I am working on a dataframe that has many custom functions, libraries, and calculations. 我正在处理一个具有许多自定义函数,库和计算的数据框。 After doing some critical calcs, I noticed some errors in calculations that should have returned a float: 在进行了一些重要的计算之后,我注意到应该返回浮点数的一些计算错误:
To inspect one of the calculations, I do the following. 要检查其中一种计算,请执行以下操作。
dFA.loc['20101120']['variable x']
which returns ( in small caps ) 返回( 小写 )
nan
Then, to confirm that this thing is what looks like a weird (small caps) numpy.nan ( True or False ) I do: 然后,要确认这件事看起来像是一个奇怪的(小写)numpy.nan( True或False ),我这样做:
dFA.loc['20101120']['variable x'] == np.nan
Which returns: 哪个返回:
False
Then I do: 然后我做:
dFA.loc['20101120']['variable x'].dtype
Which returns: 哪个返回:
dtype('float64')
Also: 也:
dFA.loc['20101120']['variable x'] > 1000
False
Also: 也:
dFA.loc['20101120']['variable x'] < 1000
False
dFA.loc['20101120']['variable x'] == np.nan
Oops. 哎呀。 NaN is never equal to NaN. NaN永远不等于NaN。
np.isnan(dFA.loc['20101120']['variable x'])
All comparisons with np.nan
evaluate to False
by definition . 根据定义,所有与np.nan
比较均np.nan
False
。
>>> np.nan == np.nan
False
>>> np.nan <= 1
False
>>> np.nan > 1
False
np.nan
is a float: np.nan
是一个浮点数:
>>> np.nan.__class__
<type 'float'>
... just a very special one. ...只是一个非常特殊的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.