# Questions tagged [nan]

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

3,632
questions

**0**

votes

**0**answers

11 views

### How add values only in empty cell of a column and these values depend on the value of another column [duplicate]

my aim is to add values to a column.
In particular I want to add number only in the empty cells of this column.
And these values are set with respect to another column.
So I have to mix nan values ...

**0**

votes

**2**answers

61 views

### how to do the mean absolute error (mae) on two dataframes with NaN in r

My data looks like this:
> dput(head(df1,25))
structure(list(Date = structure(c(16644, 16645, 16646, 16647,
16648, 16649, 16650, 16651, 16652, 16653, 16654, 16655, 16656,
16657, 16658, 16659, ...

**0**

votes

**1**answer

42 views

### Misplaced position of value counts on top of bar graph in python

I calculated missing values in my dataframe using the code:
per_B = df.isna().mean().round(4) * 100
And plotted using the following code with NaN value count on top, but the last two value count ...

**2**

votes

**0**answers

25 views

### Passing a NaN from Python through Request to Javacscript

I have a pandas array with np.NaN's in it that I convert to a dictionary for JSON
json_data = {"freq" : list(df["Data"])}
I get ready to load to a web page via flask jsonify
@...

**2**

votes

**1**answer

29 views

### Fill nan value when condition meet

I have a dataframe as shown below:
df = pd.DataFrame({'A': [1, np.nan, np.nan, np.nan, 3, 3, 3, 3, np.nan, np.nan, np.nan, 5, 5, 5, 6, 6, 6, np.nan, np.nan, np.nan, 6, 7, 8, 9, 10,np.nan, np.nan, 10, ...

**1**

vote

**2**answers

92 views

### Output is nan while it shouldn't be

I need to calculate the following:
S= 1- x^2 / 2! + x^4 / 4! - x^6 / 6! + ... + (-1)^n * x^2n / (2n)!
Where n is between 1 and 100, and x is a double.
I have the following code:
unsigned int ...

**1**

vote

**0**answers

18 views

### Excel : combined MIN + IF with 0 or #N/A

This is my problem.
I'm trying to use a MIN and IF combinaison (with CTRL + SHIFT + ENTER) because I'm looking for the minimum number of a list that respects a condition, but I don't want MIN returns ...

**1**

vote

**0**answers

9 views

### NaN Loss and Quantity of Data

everyone.
While I was training a neural network with a training dataset of 40000 objects, I was having problems related to the loss function being equal to Nan at each epoch. After sampling the ...

**0**

votes

**0**answers

75 views

### Implement NaN for ints in C++17

What would be a C++17 idiomatic way to implement NaN arithmetic for int-like types? In particular, adding (or subtracting) when either argument is NaN should yield exactly NaN.
(The standard ...

**0**

votes

**0**answers

42 views

### Can `nan` weights occur, in PyTorch, with increase in the number of a epochs?

I am trying to run a neural network model with a more number of epochs (say 800) in PyTorch. I observed that the network is generating nan values at some epoch (say 200) and may behave normally after ...

**0**

votes

**0**answers

14 views

### Pandas concat eliminating NaNs [closed]

I use pandas.concat() to concatenate a list of dataframes in which NaN values were purposely inserted; however, rows with NaNs are eliminated and this is not my desired output. What could be a ...

**1**

vote

**3**answers

37 views

### Converting a list of lists of dictionaries to a Pandas DataFrame

What might be the best way of going about working with the data structure of a list of list of dictionaries like the one I'm working with:
[[{'name': 'Export A Smooth'},
{'filter': '...

**1**

vote

**2**answers

27 views

### Select dataframe columns which contain the most valid values

I have my dataframe:
And I would like to create a subset of this dataframe with the columns in which there are the fewest NaN values (i.e. the most "valid" values)
In this case, I would ...

**0**

votes

**1**answer

35 views

### ggplot multiple columns (some columns with lots of NaN) with line and points in one plot in r

This is how my data looks like:
dput(head(dfndvi,40))
structure(list(Date = structure(c(16831, 16832, 16833, 16834,
16835, 16836, 16837, 16838, 16839, 16840, 16841, 16842, 16843,
16844, 16845, 16846,...

**0**

votes

**1**answer

29 views

### Why -nan(ind) problem is happened in my code

double power_func(double a, int b, double c) {
if (b == 0)
return 1.0;
else if (b == 1)
return a;
else
a *= c;
power_func(a, b - 1, c);
}
if i call ...

**0**

votes

**1**answer

21 views

### NaN values not replaced into dask dataframe

I'm trying to convert a dask dataframe to a pandas dataframe with the following code:
import dask.dataframe as dd
uri = "mysql+pymysql://myUser:myPassword@myHost:myPort/myDatabase"
dataframe ...

**0**

votes

**1**answer

17 views

### Python - create a column to highlight which cells of another column are NaN

This seems like it should be really easy but it is beating me.
I need to turn the following:
year_1
year_2
23
25
nan
30
34
nan
nan
nan
into the following:
year_1
year_2
y1_nan
y2_nan
23
25
0
0
...

**0**

votes

**3**answers

33 views

### Replace Unnamed values in date column with true values

I'm working on this raw data frame that needs some cleaning. So far, I have transformed this xlsx file
into this pandas dataframe:
print(df.head(16))
date technician alkalinity ...

**0**

votes

**1**answer

33 views

### Calculate the NaN average number between numeric values in a dataframe column in r

This is how my data looks like:
dput(head(dataf,40))
structure(list(Time = c(20000224, 20000225, 20000226, 20000227,
20000228, 20000229, 20000301, 20000302, 20000303, 20000304, 20000305,
20000306, ...

**-1**

votes

**0**answers

20 views

### How to deal with some columns with 50% or more missing data. remove, impute, or?

I am working on employee attrition analysis in Python, with the aim of finding which factors affect attrition. Planning to do EDA, corrplot, and feature section via classification modeling.
The ...

**0**

votes

**0**answers

16 views

### Nan loss value after few epochs with Contrastive Loss

I used a Siamese network with contrastive loss as image below, but after few epochs, the loss gave nan value with message
error :'RuntimeError: Function 'PowBackward0' returned nan values in its 0th ...

**0**

votes

**1**answer

30 views

### df.apply return NaN in pandas dataframe

I am trying to fill up a column in a dataframe with 1, 0 or -1 depending on some factors by doing it like this:
def set_order_signal(row):
if (row.MACD > row.SIGNAL) and (df.iloc[i-1].MACD ...

**-2**

votes

**0**answers

28 views

### Why NaN in js is weird in nature? [duplicate]

In js =>
NaN==NaN
false
NaN===NaN
false
Object.is(NaN,NaN)
true
What is the reason behind this kind of outcome?

**0**

votes

**0**answers

16 views

### Can you fill in (interpolate) the boundary of a NaNed out object in a Mayavi Volume_Slice plot?

I am using Mayavi in Python to plot Volume Slices (mlab.volume_slice()) of a 3D potential with a spherical particle (see image below). The potential data for the image is stored in a 3D array with ...

**1**

vote

**2**answers

23 views

### Ragged CSV read with Dask produces DtypeWarning - option to ignore "nan" on load?

I'm trying to use Dask to read a large ~500MB CSV file which contains pairs of float and str columns that are read together, resulting in two lists being read into memory at a time. This works without ...

**0**

votes

**2**answers

61 views

### I'm trying to increase a value when clicking and value returning NaN [duplicate]

I've tried a lot of stuff, however I don't know any JavaScript. All of the JavaScript in the code is copied from stack overflow and other sources. The only thing I know how to use is HTML and I'm ...

**0**

votes

**0**answers

15 views

### Try figuring out features which causes NaN loss

I'm trying to train the speech recognition model through our company's database. When I used Librispeech DB, there was no problem with model training. On the other hand, when using our company's DB, ...

**0**

votes

**1**answer

28 views

### How to substitute NaN for a text in a DataFrame?

I have a DataFrame and I need to change the content of the cells of a specific column to a text content (for example "not registered").
I am trying different options, these are some of them:
...

**0**

votes

**1**answer

22 views

### Replace the NaNs in pandas dataframe with empty_rows in pandas [duplicate]

I have the following table (df):
Col1
Col2
Col3
A1
finished
1234
A2
ongoing
1235
A3
NaN
1236
A4
finished
1237
A5
started
1238
A6
NaN
1239
I would like to replace the NaNs in the dataframe with ...

**0**

votes

**1**answer

49 views

### How to extract certain rows in a table using pandas

I have the following table (df):
Col1
Col2
Col3
A1
finished
1234
A2
ongoing
1235
A3
NaN
1236
A4
finished
1237
A5
started
1238
A6
finished
1239
I would like to extract the rows that are not ...

**0**

votes

**0**answers

13 views

### val_loss did not improve from inf

I am training a machine learning model on google colab. Previously, things were working smoothly when training on P100 and V100s. However, I have recently got A100s. This seems great, but now every ...

**0**

votes

**1**answer

21 views

### Parsing Ugly txt file in Pandas with Nan Values

I started with an ugly set of txt data of several thousand rows and have cleaned it up to resemble this:
import pandas as pd
import numpy as np
data = {'Town':['Chicago', 1.11, 1.45, 0.86, 2.68, np....

**1**

vote

**0**answers

42 views

### Is there a function in pandas to do this composite time-indexed merge operation?

I have dataframes looking like this,
df1 :
X1 X2 X3 X4
2021-02-23 15:44:20.100 NaN 0 1 Nan
2021-02-23 15:44:20.300 NaN 0 1 Nan
2021-02-23 15:44:20....

**1**

vote

**1**answer

25 views

### try to devide two data tables recives NaN in some positions

created this code for dividing 2 stock prices in order to pair trade using 2 data frames as shown below
import yfinance as yf
ticker_1, ticker_2 = 'SENEA', 'SENEB'
start_date = "2021-01-01"
...

**0**

votes

**0**answers

35 views

### How to corect the code it prints all symbols in a way that , in one dataframe ,and without any NaN or zeros?

Would you please correct the code, it prints all the symbols as well as without any NaN or zeros like?
import datetime
import pandas as pd
import numpy as np
import yfinance as yf
start = datetime....

**-6**

votes

**0**answers

46 views

### Why JavaScript is returning NaN as an odd? [duplicate]

I tried:
var is_odd_or_even = function(n){
if(n%2==0){
return `The number ${n} is even`;
}else{
return `The number ${n} is odd`;
}
};
console.log(is_odd_or_even(NaN));
...

**0**

votes

**0**answers

8 views

### Pandas drop NaN values and how to left original datatype (int) without converting [duplicate]

The most of time I have integers in my columns but if at least one row NaN value dtype becomes float. When dropping NaN float still leaves. I cannot do forced conversion to int because it happens that ...

**0**

votes

**3**answers

34 views

### Padding zeroes to columns with NaN values

I have a pandas dataframe where three columns are floats (floats64):
Num1 Num2 Num3
0 2345656 3.0 12345.0
1 3456 3.0 3100.0
2 541304 ...

**1**

vote

**2**answers

70 views

### Python find index of nan in nan-list yields error only sometimes?

For an all-nan list a = [np.nan, np.nan], a.index(np.nan) returns 0, while for the np.nan returned by b = np.nanmax(a), a.index(b) gives a ValueError. The object ids of np.nan and b are different. ...

**1**

vote

**2**answers

38 views

### Having Issues with pandas groupby.mean() not ignoring NaN as expected

Im currently trying to get the mean() of a group in my dataframe (tdf), but I have a mix of some NaN values and filled values in my dataset. Example shown below
Test #
a
b
1
1
1
1
2
NaN
1
3
2
2
4
...

**2**

votes

**0**answers

57 views

### Mark a number invalid (besides -1): Infinity or NaN? [closed]

I need to mark a number foo invalid and can't use -1 because foo can be negative. I still don't want to bother the compiler by changing the type. Both Infinity and NaN satisfy typeof === 'number', so ...

**0**

votes

**1**answer

36 views

### Cannot convert float NaN to integer after dropping NaN

I have been trying to use a script to read in data and compute the average frequency of use per year from the table (AlcData) below:
Frequency
Never
1-2 times per year
3-4 times per month
Every ...

**0**

votes

**0**answers

13 views

### Using a date index to replace NaN values

I have the following dataframe of monthly figures with missing values denoted by NaN:
My actual dataframe extends out to May 2024 so this only a partial snapshot.
In the table I want to overwrite NaN ...

**0**

votes

**1**answer

34 views

### Python/Pandas: dataframe merge and fillna

I try to merge two Pandas dataframes based on date and then ffill NaN values until specific date. I have the following data example:
df_1:
date
value1
01/12
10
02/12
20
03/12
30
04/12
40
05/12
...

**6**

votes

**2**answers

123 views

### How to write a portable constexpr std::copysign()?

In particular, it must work with NaNs as std::copysign does. Similarly, I need a constexpr std::signbit.
constexpr double copysign(double mag, double sgn)
{
// how?
}
constexpr bool signbit(...

**0**

votes

**0**answers

34 views

### AWK edge case: INF or NaN?

I'm aware this is more an inquiry of intellectual curiosity (since the code nearly makes no sense as a starting point), but I've found cases where different flavors of AWK report something completely ...

**0**

votes

**2**answers

73 views

### How can you detect NaN in Applescript?

So I have a python script that does some math that I call via do shell script like this:
return do shell script "/usr/local/bin/python3.9 /path/to/my/file.py"
(*Python file returns something ...

**0**

votes

**1**answer

19 views

### fillna() is not replacing NaN values even after using inplace=True

I am trying to replace NaN value in my 'price' column of my dataset, I tried using:
avg_price = car.groupby('make')['price'].agg(np.mean) # calculating average value of the price of each car company ...

**1**

vote

**1**answer

40 views

### Is there a way to find rows with NaN and then drop that as well as n number of rows after?

I have a spreadsheet where data is laid out in a strange way with chunks of data separated by a single empty row of NaN cells. I can remove the NaN rows with drop.na of course, however is there a way ...

**0**

votes

**1**answer

38 views

### How do I insert Infinity values into REAL/FLOAT4 Columns in DuckDB?

Say I have a table called table_1 with a single column called col_1 that is of type REAL/FLOAT4 in DuckDB. How do I insert special float values like -Infinity, NaN, and Infinity into col_1? I have ...