nan

pandas cut a series with nan values

爷,独闯天下 提交于 2020-01-15 06:20:10
问题 I would like to apply the pandas cut function to a series that includes NaNs. The desired behavior is that it buckets the non-NaN elements and returns NaN for the NaN-elements. import pandas as pd numbers_with_nan = pd.Series([3,1,2,pd.NaT,3]) numbers_without_nan = numbers_with_nan.dropna() The cutting works fine for the series without NaNs: pd.cut(numbers_without_nan, bins=[1,2,3], include_lowest=True) 0 (2.0, 3.0] 1 (0.999, 2.0] 2 (0.999, 2.0] 4 (2.0, 3.0] When I cut the series that

Count rows with 1 or more NaNs in a Dataframe

三世轮回 提交于 2020-01-13 17:09:14
问题 I have the following: print(df.isna().sum()) Which gives me: city 2 country 0 testid 0 house 1807 house_number 248 po_box 1845 zipcode 260 road 132 state 1 state_district 1817 suburb 1800 unit 1806 I want the total number of rows that have 1 or more NaN values from columns city, state, zip, and house Thanks for any suggestions. 回答1: This is how I would use isna and sum : cols = ['city', 'state', 'zip', 'house'] df[df[cols].isna().sum(axis=1) > 0] Another option is calling dropna and checking

Create sample numpy array with randomly placed NaNs

只愿长相守 提交于 2020-01-13 07:58:07
问题 For testing purposes, I'd like to create a M by N numpy array with c randomly placed NaNs import numpy as np M = 10; N = 5; c = 15; A = np.random.randn(M,N) A[mask] = np.nan I am having problems in creating a mask with c true elements, or maybe this can be done with indices directly? 回答1: You can use np.random.choice with the optional replace=False for random selection without replacement and use those on a flattened version of A (done with .ravel()), like so - A.ravel()[np.random.choice(A

MatLab Missing data handling in categorical data

半世苍凉 提交于 2020-01-13 05:45:11
问题 I am trying to put my dataset into the MATLAB [ranked,weights] = relieff(X,Ylogical,10, 'categoricalx', 'on') function to rank the importance of my predictor features. The dataset<double n*m> has n observations and m discrete (i.e. categorical) features. It happens that each observation (row) in my dataset has at least one NaN value. These NaNs represent unobserved, i.e. missing or null, predictor values in the dataset. (There is no corruption in the dataset, it is just incomplete.) relieff()

Questions regarding operations on NaN

爷,独闯天下 提交于 2020-01-11 04:54:26
问题 My SSE-FPU generates the following NaNs: When I do a any basic dual operation like ADDSD, SUBSD, MULSD or DIVSD and one of both operands is a NaN, the result has the sign of the NaN-operand and the lower 51 bits of the mantissa of the result is loaded with the lower 51 bits of the mantissa of the NaN-operand. When both operations are NaN, the result is loaded with the sign of the destination-register and the lower 51 bits of the result-mantissa is loaded with the lower 51 bits of the

MATLAB: Using interpolation to replace missing values (NaN)

会有一股神秘感。 提交于 2020-01-09 10:47:28
问题 I have cell array each containing a sequence of values as a row vector. The sequences contain some missing values represented by NaN . I would like to replace all NaNs using some sort of interpolation method, how can I can do this in MATLAB? I am also open to other suggestions on how to deal with these missing values. Consider this sample data to illustrate the problem: seq = {randn(1,10); randn(1,7); randn(1,8)}; for i=1:numel(seq) %# simulate some missing values ind = rand( size(seq{i}) ) <

MATLAB: Using interpolation to replace missing values (NaN)

隐身守侯 提交于 2020-01-09 10:46:12
问题 I have cell array each containing a sequence of values as a row vector. The sequences contain some missing values represented by NaN . I would like to replace all NaNs using some sort of interpolation method, how can I can do this in MATLAB? I am also open to other suggestions on how to deal with these missing values. Consider this sample data to illustrate the problem: seq = {randn(1,10); randn(1,7); randn(1,8)}; for i=1:numel(seq) %# simulate some missing values ind = rand( size(seq{i}) ) <

Are the bit patterns of NaNs really hardware-dependent?

醉酒当歌 提交于 2020-01-09 03:20:11
问题 I was reading about floating-point NaN values in the Java Language Specification (I'm boring). A 32-bit float has this bit format: seee eeee emmm mmmm mmmm mmmm mmmm mmmm s is the sign bit, e are the exponent bits, and m are the mantissa bits. A NaN value is encoded as an exponent of all 1s, and the mantissa bits are not all 0 (which would be +/- infinity). This means that there are lots of different possible NaN values (having different s and m bit values). On this, JLS §4.2.3 says: IEEE 754

Groovy/Grails autoconvert NaN string to double field

笑着哭i 提交于 2020-01-06 03:25:06
问题 I want to let users edit a field with double data in Grails view. I want to allow Double.NaN (to void values). There is a special char looking like a diamond with a question mark in it (in HTML) that acts like NaN, but - well - the users wont find that on their keys. In Java it works with Double.valueOf("NaN") . But typing NaN in the input field will throw a IllegalArgumentException saying "NaN" is an Unparseable Number. What method is callled for conversion? Whats the key to let it

Border-left-width returns NaN in jQuery

别等时光非礼了梦想. 提交于 2020-01-06 02:32:08
问题 I'm busy writing a small snippet of code that should allow cross-browser usage of the border-box box model. So far the basic functionality works fine, but I can't get the margin to work. It should adapt to the space that's available, but console returns a NaN and I have no idea where it comes from. Here is a fiddle. The console.log doesn't even log anything and I don't know why. Any help is greatly appreciated. 回答1: In many parts of your fiddle you have this pattern: ($(this).css("border-left