Pandas 错误 - 遇到无效值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30519487/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pandas error - invalid value encountered
提问by Ben
I'm new to Pandas. I downloaded and installed Anaconda. Then I tried running the following code via the Spyder app:
我是Pandas的新手。我下载并安装了Anaconda。然后我尝试通过 Spyder 应用程序运行以下代码:
import pandas as pd
import numpy as np
train = pd.read_csv('/Users/Ben/Documents/Kaggle/Titanic/train.csv')
train
Although this prints the dataframe as I expected, it also shows these errors
虽然这会按我的预期打印数据帧,但它也显示了这些错误
//anaconda/lib/python3.4/site-packages/pandas/core/format.py:1969: RuntimeWarning: invalid value encountered in greater
has_large_values = (abs_vals > 1e8).any()
//anaconda/lib/python3.4/site-packages/pandas/core/format.py:1970: RuntimeWarning: invalid value encountered in less
has_small_values = ((abs_vals < 10 ** (-self.digits)) &
//anaconda/lib/python3.4/site-packages/pandas/core/format.py:1971: RuntimeWarning: invalid value encountered in greater
(abs_vals > 0)).any()
Why am I getting these errors?
为什么我会收到这些错误?
EDIT: I just tested the above code in an IPythonnotebook and it works without errors. So, is there something wrong with my Spyderinstallation? Any help would be appreciated.
编辑:我刚刚在IPython笔记本中测试了上面的代码,它没有错误。那么,我的Spyder安装有问题吗?任何帮助,将不胜感激。
EDIT2: After some testing, I can read the first 5 rows of the CSV without getting the warning. So, I suspect a NaNin the 6th row for a float64type column is triggering the warning.
EDIT2:经过一些测试,我可以在没有收到警告的情况下读取 CSV 的前 5 行。因此,我怀疑类型列NaN的第 6 行中的 afloat64触发了警告。
回答by wadge
I have the same error and have decided that it is a bug. It seems to be caused by the presence of NaN values in a DataFrame in Spyder. I have uninstalled and reinstalled all packages and nothing has effected it. NaN values are supported and are completely valid in DataFrames especially if they have a DateTime index.
我有同样的错误,并确定这是一个错误。这似乎是由 Spyder 中 DataFrame 中存在 NaN 值引起的。我已经卸载并重新安装了所有软件包,但没有任何影响。支持 NaN 值并且在 DataFrame 中完全有效,特别是如果它们具有 DateTime 索引。
In the end I have settled for suppressing this warnings as follows.
最后,我决定按如下方式抑制此警告。
import warnings
warnings.simplefilter(action = "ignore", category = RuntimeWarning)

