Pandas 错误 - 遇到无效值 [英] Pandas error - invalid value encountered

查看:64
本文介绍了Pandas 错误 - 遇到无效值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是熊猫新手.我下载并安装了 Anaconda.然后我尝试通过 Spyder 应用程序运行以下代码:

I'm new to Pandas. I downloaded and installed Anaconda. Then I tried running the following code via the Spyder app:

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?

我刚刚在 IPython 笔记本中测试了上面的代码,它可以正常工作.那么,我的 Spyder 安装有问题吗?任何帮助将不胜感激.

I just tested the above code in an IPython notebook and it works without errors. So, is there something wrong with my Spyder installation? Any help would be appreciated.

经过一些测试,我可以读取 CSV 的前 5 行而不会收到警告.因此,我怀疑 float64 类型列的第 6 行中的 NaN 会触发警告.

After some testing, I can read the first 5 rows of the CSV without getting the warning. So, I suspect a NaN in the 6th row for a float64 type column is triggering the warning.

推荐答案

我有同样的错误,并确定这是一个错误.这似乎是由 Spyder 的 DataFrame 中存在 NaN 值引起的.我已经卸载并重新安装了所有软件包,但没有任何影响.NaN 值受支持并且在 DataFrame 中完全有效,尤其是在它们具有 DateTime 索引的情况下.

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.

最后,我决定按如下方式抑制此警告.

In the end I have settled for suppressing this warnings as follows.

import warnings
warnings.simplefilter(action = "ignore", category = RuntimeWarning)

这篇关于Pandas 错误 - 遇到无效值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆