nan

Why does testing `NaN == NaN` not work for dropping from a pandas dataFrame?

风格不统一 提交于 2019-12-05 05:16:00
Please explain how NaN's are treated in pandas because the following logic seems "broken" to me, I tried various ways (shown below) to drop the empty values. My dataframe, which I load from a CSV file using read.csv , has a column comments , which is empty most of the time. The column marked_results.comments looks like this; all the rest of the column is NaN, so pandas loads empty entries as NaNs, so far so good: 0 VP 1 VP 2 VP 3 TEST 4 NaN 5 NaN .... Now I try to drop those entries, only this works: marked_results.comments.isnull() All these don't work: marked_results.comments.dropna() only

RuntimeWarning: invalid value encountered in maximum

左心房为你撑大大i 提交于 2019-12-05 03:05:17
Weird behavior (bug??) in numpy. Contrary to the docs, the following code gives a RuntimeWarning: invalid value encountered in fmax a = np.random.uniform(0.1, 0.4, (5, 5)) b = np.random.uniform(0, 3.5, (5, 5)) b[0, 0] = np.nan c = np.fmax(a, b) # Same problem with c = np.maximum(a, b) I'm stuck as I need these NaNs in my arrays and now my functions stop in iPython with this damn warning (ok, they really don't stop but it's rather annoying) EDIT : numpy 1.6.1 ipython 0.13.1 I get the same issue as well. These warnings are an intentional aspect of numpy, to inform users when they may be running

Matlab - read file with varying line lengths

放肆的年华 提交于 2019-12-05 02:43:21
问题 I have a data file with varying amount of data per line that I would like to load into Matlab as an array. As an example, suppose the data file looks like 1 2 3 4 5 6 7 8 9 10 I want to read it into Matlab as an array that looks like 1 2 nan nan 3 4 5 6 7 nan nan nan 8 9 10 nan I can do this by doing a for loop over all lines of the file but my files are very large and I am looking for an efficient solution. Any ideas would be highly appreciated. If it helps, I also know an upper bound on the

SSRS Formula or expression to change NaN to 0

ε祈祈猫儿з 提交于 2019-12-05 02:26:22
I am using the following expression to work out a percentage: =Fields!Days.Value/Sum(Fields!Days.Value, "Date_month_name") Days.Value is showing as 0 however in a few of my results instead of reading 0% in my percentage column it is actually reading NaN (Not a Number). Does anyone know the exact expression forumla i need and where I should paste it in my current expression to say "Where NaN is showing, put a '0' instead?" (See image) general exception How about =IIF(Fields!Days.Value > 0,Fields!Days.Value/Sum(Fields!Days.Value, "Date_month_name"),0) I didn't have luck with the above answers.

How to check if number is NaN

落花浮王杯 提交于 2019-12-05 00:37:27
I need to test if a numeric/float value in PostgreSQL is not a number (NaN). Note that "PostgreSQL treats NaN values as equal" , so this C++ trick doesn't work . As I'm not seeing any isnan function in PostgreSQL 9.3, here is my best attempt to make one: create or replace function isnan(double precision) returns boolean as $$select $1::text = 'NaN'::text$$ language sql; Is there any better way to test for NaN s? Is there any better way to test for NaNs? Simply compare for equality: SELECT double precision 'NaN' = double precision 'NaN'; as, per the docs you linked to, Pg treats NaN s as equal.

Create sample numpy array with randomly placed NaNs

狂风中的少年 提交于 2019-12-05 00:09:29
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? 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.size, c, replace=False)] = np.nan Sample run - In [100]: A Out[100]: array([[-0.35365726, 0.26754527, -0

Why does Assert.AreEqual(1.0, double.NaN, 1.0) pass?

那年仲夏 提交于 2019-12-04 23:54:43
Short question, why does Assert.AreEqual(1.0, double.NaN, 1.0) pass? Whereas Assert.AreEqual(1.0, double.NaN) fails. Is it a bug in MSTest (Microsoft.VisualStudio.QualityTools.UnitTestFramework) or am I missing something here? Best regards, Egil. Update: Should probably add, that the reason behind my question is, that I have a bunch of unit tests that unfortunately passed due to the result of some linear algebraic matrix operation being NaN or (+/-)Infinity. The unit tests are fine, but since Assert.AreEqual on doubles with a delta will pass when actual or/and expected are NaN or Infinity, I

Exporting ints with missing values to csv in Pandas

て烟熏妆下的殇ゞ 提交于 2019-12-04 23:11:46
When saving a Pandas DataFrame to csv, some integers are getting converted in floats. It happens where a column of floats has missing values ( np.nan ). Is there a simple way to avoid it? (Especially in an automatic way - I often deal with many columns of various data types.) For example import pandas as pd import numpy as np df = pd.DataFrame([[1,2],[3,np.nan],[5,6]], columns=["a","b"], index=["i_1","i_2","i_3"]) df.to_csv("file.csv") yields ,a,b i_1,1,2.0 i_2,3, i_3,5,6.0 What I would like to get is ,a,b i_1,1,2 i_2,3, i_3,5,6 EDIT: I am fully aware of Support for integer NA - Pandas Caveats

How to count nan values in a pandas DataFrame?

倖福魔咒の 提交于 2019-12-04 22:49:53
What is the best way to account for (not a number) nan values in a pandas DataFrame? The following code: import numpy as np import pandas as pd dfd = pd.DataFrame([1, np.nan, 3, 3, 3, np.nan], columns=['a']) dfv = dfd.a.value_counts().sort_index() print("nan: %d" % dfv[np.nan].sum()) print("1: %d" % dfv[1].sum()) print("3: %d" % dfv[3].sum()) print("total: %d" % dfv[:].sum()) Outputs: nan: 0 1: 1 3: 3 total: 4 While the desired output is: nan: 2 1: 1 3: 3 total: 6 I am using pandas 0.17 with Python 3.5.0 with Anaconda 2.4.0. If you want to count only NaN values in column 'a' of a DataFrame df

Can float (or double) be set to NaN?

你说的曾经没有我的故事 提交于 2019-12-04 22:28:45
Note: Similar to Can an integer be NaN in C++? I understand this has little practical purpose, but can a float or double be set to NaN ? The Float object contains a static value, which is a float type, called NaN . So float myFloat = Float.NaN; gives you what you are asking. http://download.oracle.com/javase/6/docs/api/java/lang/Float.html#NaN Sure! NaN is a static constant in the Float and Double classes. double x = Double.NaN; Yes float f = Float.NaN; See the doc for more info. Note that if you want to compare a number to NaN, you should use isNan() . Despite your question above, this does