nan

Replace NaN in DataFrame index

一笑奈何 提交于 2019-12-01 12:17:47
I have a DataFrame which looks like this: one | two a | 2 | 5 b | 3 | 6 NaN | 0 | 0 How do I replace the NaN in the index with a string, say "No label"? I tried: df = df.replace(np.NaN, "No label") and df.index = df.index.replace(np.NaN, "No label") But got TypeError: expected string or buffer You can process the original index as a Series first and then re-assign the index: import pandas as pd import numpy as np df = pd.DataFrame({'one': [2, 3, 0], 'two': [5, 6, 0]}, index=['a', 'b', np.nan]) df.index = pd.Series(df.index).replace(np.nan, 'No label') print df Output: one two a 2 5 b 3 6 No

Is it possible to make isnan() work in gfortran -O3 -ffast-math?

こ雲淡風輕ζ 提交于 2019-12-01 11:35:16
I would like to compile a program with gfortran and -O3 -ffast-math enabled, since it gives a nice performance boost. I was rather confused, that gfortran's isnan() catched some NaN's but not all of them. After reading Checking if a double (or float) is NaN in C++ how do I make a portable isnan/isinf function Negative NaN is not a NaN? I am under the impression that people are able to check for NaN's in C via bit-fiddling even with fast-math enabled. However, this puzzles me since fast-math can result in incorrect output for programs that depend on an exact implementation of IEEE or ISO rules

df.fillna(0) command won't replace NaN values with 0

百般思念 提交于 2019-12-01 09:19:40
I'm trying to replace the NaN values generated in the code below to 0. I don't understand what the below won't work. It still keeps the NaN values. df_pubs=pd.read_sql("select Conference, Year, count(*) as totalPubs from publications where year>=1991 group by conference, year", db) df_pubs['Conference'] = df_pubs['Conference'].str.encode('utf-8') df_pubs = df_pubs.pivot(index='Conference', columns='Year', values='totalPubs') df_pubs.fillna(0) print df_pubs print df produces this: Year 1991 \ Conference 223 10th Anniversary Colloquium of UNU/IIST NaN 15. WLP NaN 1999 ACM SIGMOD Workshop on

Is it possible to make isnan() work in gfortran -O3 -ffast-math?

柔情痞子 提交于 2019-12-01 08:04:49
问题 I would like to compile a program with gfortran and -O3 -ffast-math enabled, since it gives a nice performance boost. I was rather confused, that gfortran's isnan() catched some NaN's but not all of them. After reading Checking if a double (or float) is NaN in C++ how do I make a portable isnan/isinf function Negative NaN is not a NaN? I am under the impression that people are able to check for NaN's in C via bit-fiddling even with fast-math enabled. However, this puzzles me since fast-math

Replace NaN sequence according to values before and after the sequence

房东的猫 提交于 2019-12-01 07:37:54
问题 I would appreciate if someone can help me with this problem... I have a vector A = [NaN 1 1 1 1 NaN NaN NaN NaN NaN 2 2 2 NaN NaN NaN 2 NaN NaN 3 NaN NaN]; I would like to fill the NaN values according to this logic. 1) if the value that precedes the sequence of NaN is different from the one that follows the sequence => assign half of the NaNs to the first value and half to the second value 2) if the NaN seqence is between 2 equal values => fill the NaN with that value. A should be then: A =

Why isn't NaN finite?

笑着哭i 提交于 2019-12-01 07:35:27
Testing the isFinite function I see that NaN is an infinite number (even if it's not a number :-) ). isFinite(NaN) // returns false What's the logic behind this? Why isn't NaN finite? As Dave Newton said, NaN is not a number, and then you have to consider that it isn't finite nor infinite. The same occurs to these: NaN > 0 // false NaN < 0 // false You might want to read these articles: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite Because it is not a numeric value..

How can I manually set the bit value of a float that equates to NaN?

时间秒杀一切 提交于 2019-12-01 07:34:10
I'm trying to run some tests with conversions and castings of floats to other types and I want to set my float variable to different values of nan. "a bit-wise example of a IEEE floating-point standard single precision (32-bit) NaN would be: s111 1111 1axx xxxx xxxx xxxx xxxx xxxx where s is the sign (most often ignored in applications), a determines the type of NaN, and x is an extra payload (most often ignored in applications). If a = 1, it is a quiet NaN; if a is zero and the payload is nonzero, then it is a signaling NaN" Basically I want to find a way to set the payload or xxxx's of the

Nullable double NaN comparison in C#

大城市里の小女人 提交于 2019-12-01 06:23:26
I have 2 nullable doubles, an expected value and an actual value (let's call them value and valueExpected). A percentage is found using 100 * (value / valueExpected). However, if valueExpected is zero, it returns NaN. Everything good so far. Now, what do I do if I need to check the value, to see if it is NaN? Normally one could use: if (!Double.IsNaN(myDouble)) But this doesn't work with nullable values (IsNaN only works with non-nullable variables). I have changed my code to do the check (valueExpected == 0), but I'm still curious - is there any way to check for a nullable NaN? Edit: When I

How can I manually set the bit value of a float that equates to NaN?

不羁的心 提交于 2019-12-01 05:53:53
问题 I'm trying to run some tests with conversions and castings of floats to other types and I want to set my float variable to different values of nan. "a bit-wise example of a IEEE floating-point standard single precision (32-bit) NaN would be: s111 1111 1axx xxxx xxxx xxxx xxxx xxxx where s is the sign (most often ignored in applications), a determines the type of NaN, and x is an extra payload (most often ignored in applications). If a = 1, it is a quiet NaN; if a is zero and the payload is

Why isn't NaN finite?

丶灬走出姿态 提交于 2019-12-01 05:27:29
问题 Testing the isFinite function I see that NaN is an infinite number (even if it's not a number :-) ). isFinite(NaN) // returns false What's the logic behind this? Why isn't NaN finite? 回答1: As Dave Newton said, NaN is not a number, and then you have to consider that it isn't finite nor infinite. The same occurs to these: NaN > 0 // false NaN < 0 // false You might want to read these articles: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN https://developer