nan

How to get row, column indices of all non-NaN items in Pandas dataframe

随声附和 提交于 2019-12-24 15:58:23
问题 How do I iterate over a dataframe like the following and return the non-NaN value locations as a tuple. i.e. df: 0 1 2 0 NaN NaN 1 1 1 NaN NaN 2 NaN 2 NaN I would get an output of [(0, 1), (2, 0), (1, 2)]. Would the best way be to do a nested-for loop? Or is there an easier way I'm unaware of through Pandas. 回答1: Assuming you don't need in order, you could stack the nonnull values and work on index values. In [26]: list(df[df.notnull()].stack().index) Out[26]: [(0L, '2'), (1L, '0'), (2L, '1')

Getting NaN if variable has null value

爱⌒轻易说出口 提交于 2019-12-24 15:42:41
问题 Here, I am getting record through ajax and json. I am getting value if the variable have. But, If variable "performance" have null value, it shows NaN . Instead of NaN , I want to print number value like, 00.00 . Is that possible? If yes then how? Thank you. My code, function emp_month_perf(){ jQuery.ajax({ url: "<?php echo base_url(); ?>grade_tasks/emp_monthly_performance", data:'', type:"GET", dataType: "json", success:function(data){ var total_month_earn = data.total_earn_point; var total

How can I get all the index of all the NaNs of a list?

扶醉桌前 提交于 2019-12-24 12:43:59
问题 I am trying to make a list with the index of all NaNs in the list a . The problem is that the list ind doesn't fill with anything. It works if instead of NaN , I put a random string like c . import numpy as np a=[1, 2, 3, 4, np.nan, np.nan, 2, np.nan] ind=[] for i in range(0,len(a)): if a[i]==float("NaN"): ind.append(i) print ind 回答1: If you're using NumPy, you should really start using arrays, and get out of the habit of manually looping at Python level. Manual loops are typically about 100

When is $render() of ngModel called with real data?

北城以北 提交于 2019-12-24 08:37:26
问题 I am writing a directive to cooperate with ngModel. As shown in the example, I set the $render function on the controller to my function. When the code initializes, it is invoked twice, the first time with $modelValue and $viewValue set to NaN, and then a second time with the actual value of the model. The problem is, NaN is a bear to test for. The function isNaN() is worthless, so far as I can see (it returns false for [""] but true for ["."] ) and Number.isNaN() is not widely supported. Any

Squareroot returning not a number in C++

蓝咒 提交于 2019-12-24 07:59:11
问题 In the program below, I am trying to calculate the distance between two points. For this, I have made two Point objects. In the method that returns the distance, I have used the distance formula to calculate distance between two points in space. However, every time I run the program, I get a not a number value, which shouldn't be there. Please help. #include <iostream> #include <cstdlib> #include <cstdio> #include <cmath> using namespace std; class Point { public: Point(int a, int b); ~Point(

Is there is a more concise representation of Infinity in JSON than 1e309?

半世苍凉 提交于 2019-12-24 07:18:49
问题 It's the smallest I could find. 回答1: The JSON RFC ( http://tools.ietf.org/html/rfc4627 ) states that NaN, Positive Infinity and Negative Infinity cannot be represented in JSON: Numeric values that cannot be represented as sequences of digits (such as Infinity and NaN) are not permitted. I don't know where you're getting 1*10^309 from, because Javascript's maximum exact integer value is 2^53. When you say "concise" do you actually mean "succinct"? 来源: https://stackoverflow.com/questions

Pandas crosstab matrix dot nansum

ぃ、小莉子 提交于 2019-12-24 02:10:36
问题 i'm looking for help creating a sub-dataframe from an existing dataframe using a np.nansum-like function. I want to convert this table into a matrix of non-null column sums: dan ste bob t1 na 2 na t2 2 na 1 t3 2 1 na t4 1 na 2 t5 na 1 2 t6 2 1 na t7 1 na 2 For example, when 'dan' is not-null (t-2,3,4,6,7) the sum of 'ste' is 2 and 'bob' is 5. When 'ste' is not-null the sum of 'dan' is 4. dan ste bob dan 0 2 5 ste 4 0 2 bob 4 1 0 Any ideas? Thanks in advance! I ended up using a modified

Removing NaN Values from Array and shift left

心已入冬 提交于 2019-12-23 12:49:31
问题 I have a 34 x 1096 array that has NaN values. A = NaN 0.2500 NaN 0.3750 NaN NaN 0.1100 NaN 0.4310 0.1250 NaN 0.1250 0.2500 0.3750 0.4310 And I want A = 0.2500 0.3750 NaN NaN NaN 0.1100 0.4310 0.1250 NaN NaN 0.1250 0.2500 0.3750 0.4310 NaN Whats a simple way to do this? 回答1: a simple way will be to use a for loop with ~isnan on each row, for example: B=NaN(size(A)); for n=1:size(A,1) B(n,1:sum(~isnan(A(n,:))))=A(n,~isnan(A(n,:))); end B = 0.2500 0.3750 NaN NaN NaN 0.1100 0.4310 0.1250 NaN NaN

Pandas reading NULL as a NaN float instead of str [duplicate]

£可爱£侵袭症+ 提交于 2019-12-23 12:42:09
问题 This question already has answers here : How to treat NULL as a normal string with pandas? (4 answers) Closed last year . Given the file: $ cat test.csv a,b,c,NULL,d e,f,g,h,i j,k,l,m,n Where the 3rd column is to be treated as str . When I did a string function on the column, pandas has read the NULL str as a NaN float: >>> import pandas as pd >>> df = pd.read_csv('test.csv', names=[0,1,2,3,4], dtype={0:str, 1:str, 2:str, 3:str, 4:str}) >>> df[3].apply(str.strip) Traceback (most recent call

What is the difference between IND and NAN numbers

只愿长相守 提交于 2019-12-23 10:25:13
问题 A NAN value means Not A Number and IND value means Indeterminate number. But what is the difference between these two. How can we represent both in c++. 回答1: But what is the difference between these two. They are both the same thing. Some platforms choose to display a non-number as some variant of NaN , while others choose to display it as some variant of IND . How can we represent both in c++. std::numeric_limits<double>::quiet_NaN() (or float or long double , if you prefer). 回答2: If your