简体   繁体   English

奇怪的行为:熊猫数据框中的一个numpy nan显示为dtype('float64')

[英]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( TrueFalse ),我这样做:

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.

相关问题 在 pandas 中,将 float64(具有 NaN 值)转换为字符串(不显示小数) - In pandas, convert float64 (with NaN values) to strings (with no decimals showing) 如何在我的 numpy 数组中找到 NaN/无穷大/对于 dtype(&#39;float64&#39;) 来说太大的值? - How do I find the values in my numpy array that are NaN/infinity/too large for dtype('float64')? DataFrame之和的奇怪output。 为什么 df.sum() 返回 Series([], dtype: float64)? - Strange output of sum of DataFrame. Why does df.sum() return Series([], dtype: float64)? 使用dtype float64创建pandas数据框会更改其条目的最后一位数(相当大的数字) - creating pandas dataframe with dtype float64 changes last digit of its entry (a fairly large number) 为什么numpy.dtype(&#39;float64&#39;)特别? - Why is numpy.dtype('float64') special? 使用 dtype 将 dataframe 从 float64 转换为 object - converting a dataframe from float64 to object using dtype Pandas DataFrame Float64 - 点精度 - Pandas DataFrame Float64 - Point Precision 在Python中二进制化float64 Pandas Dataframe - Binarize a float64 Pandas Dataframe in Python float32 / float64 numpy变量的不同行为 - Different behavior of float32/float64 numpy variables numpy / pandas:测试float64数组等于有效位数 - numpy/pandas: test float64 arrays are equal up to significant digits
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM