Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas error - invalid value encountered

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?

EDIT: 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.

EDIT2: 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.

like image 986
Ben Avatar asked May 29 '15 00:05

Ben


People also ask

What is Runtimewarning invalid value encountered in Double_scalars?

Why Is the Runtimewarning: Invalid Value Encountered in double_scalars Error Happening? The runtimewarning: invalid value encountered in double_scalars error happens when web developers try to perform certain mathematical operations that include numbers at the opposite end of the spectrum.

What is Double_scalars?

A double scalar is a value of type double . It is called scalar to differentiate it in numpy from double arrays.

How do you handle Runtimewarning invalid value encountered in true<UNK>Divide?

Solution: We can fix this Runtime Warning by using seterr method which takes invalid as a parameter and assign ignore as a value to it. By that, it can hide the warning message which contains invalid in that.


1 Answers

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) 
like image 167
wadge Avatar answered Sep 26 '22 02:09

wadge