nan

StandardScaler -ValueError: Input contains NaN, infinity or a value too large for dtype('float64')

狂风中的少年 提交于 2019-12-07 21:06:02
问题 I have the following code X = df_X.as_matrix(header[1:col_num]) scaler = preprocessing.StandardScaler().fit(X) X_nor = scaler.transform(X) And got the following errors: File "/Users/edamame/Library/python_virenv/lib/python2.7/site-packages/sklearn/utils/validation.py", line 54, in _assert_all_finite " or a value too large for %r." % X.dtype) ValueError: Input contains NaN, infinity or a value too large for dtype('float64'). I used: print(np.isinf(X)) print(np.isnan(X)) which gives me the

R: Why does mean(NA, na.rm = TRUE) return NaN

我怕爱的太早我们不能终老 提交于 2019-12-07 20:09:54
问题 When estimating the mean with a vector of all NA's we get an NaN if na.rm = TRUE . Why is this, is this flawed logic or is there something I'm missing? Surely it would make more sense to use NA than NaN ? Quick example below mean(NA, na.rm = TRUE) #[1] NaN mean(rep(NA, 10), na.rm = TRUE) #[1] NaN 回答1: It is a bit pity that ?mean does not say anything about this. My comment only told you that applying mean on an empty "numeric" results in NaN without more reasoning. Rui Barradas's comment

Sort matrix with NaNs, extract index vectors and move NaNs to the end

时间秒杀一切 提交于 2019-12-07 18:54:51
问题 mockup = [3,5,nan,2,4,nan,10,nan]; How can I sort this vector in a descending order while ignoring the NaNs? The resulting vector must have the same length as mockup , i.e. I need to put all NaNs at the end. The result should like like this: mockupSorted = [10,5,4,3,2,NaN,NaN,NaN] Actually, I am interested in the respective indices, i.e. the second output vector of the sort function. So, I am looking for mockupSortedIdx = [7,2,5,1,4,NaN,NaN,NaN] 回答1: You can use the two outputs of sort and

NaNs produced in deSolve package

狂风中的少年 提交于 2019-12-07 18:43:42
问题 I have got a system of 8 differential equations that I am trying to solve using deSolve in R. It just returns NaN after the first few steps and doesn't solve it further. I tried various differential solvers like lsoda (default), bdf , adams , rk4 etc, but it didn't help. Here is the sample R code: library(deSolve) daero = c(5.29,4.16,2.49,1.53,0.7,0.41,0.21)*10^-4 rho = rep(1.27,7) dgeo = daero * sqrt(1/rho) r0 = dgeo/2 Fr = c(0.188,0.297,0.274,0.181,0.032,0.013,0.015) X0 = Fr*200*10^-6 N0 =

Cannot Fill NaN with zeros in a Pandas Dataframe

风格不统一 提交于 2019-12-07 17:55:31
问题 I have the following problem: I am reading a csv file with missing values by using pd.read_csv(f_name, sep=sep, header=hdr, parse_dates=True, index_col=date_col, quotechar=quote) The dataframe I get has 'nan's in it (I was expecting 'NaN's with the Upper cases). Now if I try to replace those nan's with zerosby using df.fillna(0) my df doesn't change (I still see nan's in it) My guess is that fillna is not working because I have nan (lowercase) instead of NaN (uppercase). Am I correct? If yes,

Pandas Lambda Function with Nan Support

偶尔善良 提交于 2019-12-07 11:36:05
问题 I am trying to write a lambda function in Pandas that checks to see if Col1 is a Nan and if so, uses another column's data. I have having trouble getting code (below) to compile/execute correctly. import pandas as pd import numpy as np df=pd.DataFrame({ 'Col1' : [1,2,3,np.NaN], 'Col2': [7, 8, 9, 10]}) df2=df.apply(lambda x: x['Col2'] if x['Col1'].isnull() else x['Col1'], axis=1) Does anyone have any good idea on how to write a solution like this with a lambda function or have I exceeded the

Angular Date filter is not workig in firefox

南笙酒味 提交于 2019-12-07 09:42:55
问题 I am using date filter to format my date in my angular application. In Firefox, I'm getting the date value as undefined NaN, NaN NaN:NaN:NaN PM In Chrome its works perfectly as Jun 25, 2014 7:22:47 AM My code is as follows. var formatDate = new Date(info.list[i].date); var newDate=$filter('date')(formatDate, 'medium'); How do I get it to work in Firefox? 回答1: I ran into this issue and found that the problem was Chrome/Opera and Firefox/Safari have different tolerances for creating a new

Why is `NaN` considered “smaller” than `-np.inf` in numpy?

一曲冷凌霜 提交于 2019-12-07 06:27:30
问题 What is the reason that NaN 's are considered less than -np.inf in any comparisons involving np.min or np.argmin ? import numpy as np In [73]: m = np.array([np.nan, 1., 0., -np.inf]) In [74]: n = np.array([-np.inf, 1., 0., np.nan]) # Huh?? In [75]: np.min(m) Out[75]: nan In [76]: np.min(n) Out[76]: nan # Same for np.argmin In [77]: np.argmin(m) Out[77]: 0 In [78]: np.argmin(n) Out[78]: 3 # Its all false! In [79]: np.nan < -np.inf Out[79]: False In [80]: np.nan > -np.inf Out[80]: False # OK,

What is the difference between combine_first and fillna?

☆樱花仙子☆ 提交于 2019-12-07 04:12:56
问题 These two functions seem equivalent to me. You can see that they accomplish the same goal in the code below, as columns c and d are equal. So when should I use one over the other? Here is an example: import pandas as pd import numpy as np df = pd.DataFrame(np.random.randint(0, 10, size=(10, 2)), columns=list('ab')) df.loc[::2, 'a'] = np.nan Returns: a b 0 NaN 4 1 2.0 6 2 NaN 8 3 0.0 4 4 NaN 4 5 0.0 8 6 NaN 7 7 2.0 2 8 NaN 9 9 7.0 2 This is my starting point. Now I will add two columns, one

Blank when NaN in jqGrid cells

佐手、 提交于 2019-12-07 03:46:05
问题 How to set blank instead of NaN in jqGrid cells ? Using formatter ? Is there an example? 回答1: This is REALLY old but the jqGrid documentation didn't have an easy answer and this question pulls up first in Google results when I was looking for the same answer. I was able to display a blank cell instead of a 0 when using the predefined formatter option for an integer using this code: { name: 'Quantity', formatter: 'integer', formatoptions: { defaultValue: ''} } The defaultValue is just set to