nan

Pandas Replace NaN with blank/empty string

此生再无相见时 提交于 2019-11-28 15:09:24
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 unread 2 c "" read nEO import numpy as np df1 = df.replace(np.nan, '', regex=True) This might help. It will replace all NaNs with an empty string. fantabolous Slightly shorter is: df = df.fillna('') or just df.fillna('',inplace=True) This will fill na's (e.g. NaN's) with ''. If you want to fill a single column, you can use: df[column1] = df.column1.fillna('') If you are reading the dataframe from a file

Parsing “NA” entries as NaN values when reading in a pandas dataframe

痞子三分冷 提交于 2019-11-28 14:47:54
i am new to pandas. I have loaded csv using pandas.read_csv. i have tried not to specify dtype but it was way too slow. since it is a very large file, i also specified data type. however, sometimes in numeric columns, it contains "NA". i have used na_values = ['NA'], will it affect my data frame? i still want to preserve these rows. my question is if i specify data type and add na_values = ['NA'], will NA be tossed away? if yes, how can i maintain similar process time without losing these na? thank you very much! From the pd.read_csv docs: na_values : scalar, str , list -like, or dict ,

Update pandas dataframe based on matching columns of a second dataframe

大兔子大兔子 提交于 2019-11-28 14:10:17
I have two pandas dataframes ( df_1 , df_2 ) with the same columns, but in one dataframe ( df_1 ) some values of one column are missing. So I want to fill in those missing values from df_2 , but only when the the values of two columns match. Here is a little example what my data looks like: df_1: df_2: I tried to add the missing values with: df_1.update(df_2, overwrite=False) But the problem is, that it will fill in the values, even when just one column matches. I want to fill in the value when the columns "housenumber" AND "street" matches. I think you need set_index for Multiindex in both

Dealing with NaN's in matlab functions

独自空忆成欢 提交于 2019-11-28 14:08:14
I was wondering if matlab has a built in way to deal with NaN 's in function calls. More specifically, I am trying to take the mean of a vector that has a NaN in it. For example, in R > x = c(1,2,3,4,NA) > mean(x) [1] NA > mean(x,na.rm=TRUE) [1] 2.5 Is there something comprable to this in Matlab that is in one line (I don't want to write my own function nor have to loop to find NaN 's before calculating the mean). Also, I do not have access to the statistics toolbox so I can't use something like nanmean() . You could do something like mean(x(~isnan(x))) . If you want you could also write a

divide by zero - c programming

柔情痞子 提交于 2019-11-28 13:28:13
I have a question about the next code: int main { double x = 0; double y = 0/x; if(y==1) {.....} .... .... return 0; } When I run the code on my computer, I get no runtime error and I see that y = -nan(0x8000000000000) . Why it is not a runtime error to divide by zero? Additionally, when I change the first line to int x = 0; now there is a runtime error. What is the difference? You can't rely on this "working" (i.e. doing the same thing all the time, portably) at all, it's undefined behavior in C for the second case, and also for the first if your implementation doesn't define __STDC_IEC_559__

PHP: How to encode infinity or NaN numbers to JSON?

我的未来我决定 提交于 2019-11-28 13:18:14
Apparently, infinity and NaN are not a part of JSON specification, so this PHP code: $numbers = array(); $numbers ['positive_infinity'] = +INF; $numbers ['negative_infinity'] = -INF; $numbers ['not_a_number'] = NAN; $array_print = print_r ($numbers, true); $array_json = json_encode ($numbers); echo "\nprint_r(): $array_print"; echo "\njson_encode(): $array_json"; Produces this: PHP Warning: json_encode(): double INF does not conform to the JSON spec, encoded as 0 in /home/septi/test.php on line 8 PHP Warning: json_encode(): double -INF does not conform to the JSON spec, encoded as 0 in /home

in operator, float(“NaN”) and np.nan

青春壹個敷衍的年華 提交于 2019-11-28 13:15:50
I used to believe that in operator in Python checks the presence of element in some collection using equality checking == , so element in some_list is roughly equivalent to any(x == element for x in some_list) . For example: True in [1, 2, 3] # True because True == 1 or 1 in [1., 2., 3.] # also True because 1 == 1. However, it is well-known that NaN is not equal to itself. So I expected that float("NaN") in [float("NaN")] is False . And it is False indeed. However, if we use numpy.nan instead of float("NaN") , the situation is quite different: import numpy as np np.nan in [np.nan, 1, 2] # True

PHP returning NaN

岁酱吖の 提交于 2019-11-28 13:13:58
I have a function that calculates the distance between two GPS coordinates. I then get all the coordinates from the database and loop through them all to get the distance between the current one and the previous one, then add that to an array for the specific GPS device. For some reason it is return NaN. I have tried casting it as a double, an int, and rounding the number. Here is my PHP code: function distance($lat1, $lon1, $lat2, $lon2) { $lat1 = round($lat1, 3); $lon1 = round($lon1, 3); $lat2 = round($lat2, 3); $lon2 = round($lon2, 3); $theta = $lon1 - $lon2; $dist = sin(deg2rad($lat1)) *

Having parameter (constant) variable with NaN value in FORTRAN

风格不统一 提交于 2019-11-28 12:14:22
Is it possible to set a parameter variable with NaN? and have that in a particular module. I want to use it for initialization of some other variables. Therefore, I'll be faced with a run-time error, if they are not updated, rather than simulations running with some random numbers. I am using GFORTRAN. It is possible. You first have to find out which bit pattern represents one of the possible NaN values. You can store the bit pattern in an integer: use, intrinsic :: iso_fortran_env real(real64) x integer(int64) i x = 0 x = 0/x print *, x print *, transfer(x, i) end It gives: -2251799813685248

What are the other NaN values?

陌路散爱 提交于 2019-11-28 12:07:39
The documentation for java.lang.Double.NaN says that it is A constant holding a Not-a-Number (NaN) value of type double . It is equivalent to the value returned by Double.longBitsToDouble(0x7ff8000000000000L) . This seems to imply there are others. If so, how do I get hold of them, and can this be done portably? To be clear, I would like to find the double values x such that Double.doubleToRawLongBits(x) != Double.doubleToRawLongBits(Double.NaN) and Double.isNaN(x) are both true. You need doubleToRawLongBits rather than doubleToLongBits . doubleToRawLongBits extracts the actual binary