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

查看:123
本文介绍了 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值受支持并且在DataFrames中完全有效,尤其是当它们具有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天全站免登陆