Questions tagged [nan]

NaN is an abbreviation for "Not a Number". NaN is sometimes not equal to itself.

NaN (Not a Number) is a value of the numeric data type representing an undefined or unrepresentable value, especially in floating-point calculations. Systematic use of NaNs was introduced by the IEEE 754 floating-point standard in 1985, along with the representation of other non-finite quantities such as infinity.

A common issue of NaN in many programming languages is that NaN is not equal to itself.

3468 questions
983
votes
12 answers

How to drop rows of Pandas DataFrame whose value in a certain column is NaN

I have this DataFrame and want only the records whose EPS column is not NaN: >>> df STK_ID EPS cash STK_ID RPT_Date 601166 20111231 601166 NaN NaN 600036 20111231 600036 NaN 12 600016 20111231 600016 …
bigbug
  • 40,984
  • 35
  • 71
  • 92
599
votes
22 answers

Set value for particular cell in pandas DataFrame using index

I've created a Pandas DataFrame df = DataFrame(index=['A','B','C'], columns=['x','y']) and got this x y A NaN NaN B NaN NaN C NaN NaN Then I want to assign value to particular cell, for example for row 'C' and column 'x'. I've…
Mitkp
  • 6,087
  • 3
  • 11
  • 7
557
votes
22 answers

How to check if any value is NaN in a Pandas DataFrame

In Python Pandas, what's the best way to check whether a DataFrame has one (or more) NaN values? I know about the function pd.isnan, but this returns a DataFrame of booleans for each element. This post right here doesn't exactly answer my question…
hlin117
  • 16,266
  • 25
  • 66
  • 87
532
votes
15 answers

How to replace NaN values by Zeroes in a column of a Pandas Dataframe?

I have a Pandas Dataframe as below: itm Date Amount 67 420 2012-09-30 00:00:00 65211 68 421 2012-09-09 00:00:00 29424 69 421 2012-09-16 00:00:00 29877 70 421 2012-09-23 00:00:00 30990 71 421 2012-09-30…
George Thompson
  • 5,647
  • 3
  • 13
  • 15
452
votes
30 answers

How do you check that a number is NaN in JavaScript?

I’ve only been trying it in Firefox’s JavaScript console, but neither of the following statements return true: parseFloat('geoff') == NaN; parseFloat('geoff') == Number.NaN;
Paul D. Waite
  • 89,393
  • 53
  • 186
  • 261
386
votes
20 answers

Checking if a double (or float) is NaN in C++

Is there an isnan() function? PS.: I'm in MinGW (if that makes a difference). I had this solved by using isnan() from , which doesn't exist in , which I was #includeing at first.
hasen
  • 148,751
  • 62
  • 182
  • 223
319
votes
18 answers

How to turn NaN from parseInt into 0 for an empty string?

Is it possible somehow to return 0 instead of NaN when parsing values in JavaScript? In case of the empty string parseInt returns NaN. Is it possible to do something like that in JavaScript to check for NaN? var value = parseInt(tbb) == NaN ? 0 :…
Joper
  • 7,389
  • 19
  • 49
  • 78
297
votes
7 answers

How do you test to see if a double is equal to NaN?

I have a double in Java and I want to check if it is NaN. What is the best way to do this?
Eric Wilson
  • 51,818
  • 71
  • 192
  • 262
294
votes
11 answers

What is the rationale for all comparisons returning false for IEEE754 NaN values?

Why do comparisons of NaN values behave differently from all other values? That is, all comparisons with the operators ==, <=, >=, <, > where one or both values is NaN returns false, contrary to the behaviour of all other values. I suppose this…
starblue
  • 51,675
  • 14
  • 88
  • 146
276
votes
5 answers

How to select rows with one or more nulls from a pandas DataFrame without listing columns explicitly?

I have a dataframe with ~300K rows and ~40 columns. I want to find out if any rows contain null values - and put these 'null'-rows into a separate dataframe so that I could explore them easily. I can create a mask explicitly: mask = False for col in…
Lev Selector
  • 3,091
  • 3
  • 14
  • 8
274
votes
8 answers

Pandas Replace NaN with blank/empty string

I have a Pandas Dataframe as shown below: 1 2 3 0 a NaN read 1 b l unread 2 c NaN read I want to remove the NaN values with an empty string so that it looks like so: 1 2 3 0 a "" read 1 b l …
user1452759
  • 6,778
  • 11
  • 35
  • 49
267
votes
13 answers

Removing nan values from an array

I want to figure out how to remove nan values from my array. My array looks something like this: x = [1400, 1500, 1600, nan, nan, nan ,1700] #Not in this exact configuration How can I remove the nan values from x?
Dax Feliz
  • 9,379
  • 8
  • 22
  • 30
224
votes
5 answers

Is it possible to set a number to NaN or infinity?

Is it possible to set an element of an array to NaN in Python? Additionally, is it possible to set a variable to +/- infinity? If so, is there any function to check whether a number is infinity or not?
Bob
  • 9,535
  • 20
  • 81
  • 129
220
votes
11 answers

pandas DataFrame: replace nan values with average of columns

I've got a pandas DataFrame filled mostly with real numbers, but there is a few nan values in it as well. How can I replace the nans with averages of columns where they are? This question is very similar to this one: numpy array: replace nan values…
piokuc
  • 22,730
  • 9
  • 64
  • 94
189
votes
9 answers

How to find which columns contain any NaN value in Pandas dataframe

Given a pandas dataframe containing possible NaN values scattered here and there: Question: How do I determine which columns contain NaN values? In particular, can I get a list of the column names containing NaNs?
denvar
  • 4,951
  • 8
  • 28
  • 54
1
2 3
99 100