Trying to determine if npy.nan is present in a pandas.Series
1. The code I've created to replicate and test what I'm trying to accomplish:
ser = pnd.Series(['1',None, 2, npy.nan], index=['2001','2002','2003','2004'])
serTest = ser.isin([npy.nan]) == True
serTest assigned
2001 False
2002 False
2003 False
2004 True
2. Code that is showing inconsistent behavior:
(data's coming from an csv file, The World Bank)
I'm attempting to read any relevant values from a csv file that're of type, npy.nan. To verify the pertinent cells for its type and to troubleshoot the problem I'm experiencing, I'm using the following code, where data is a panda series type, containing the index (year), and a float (gross domestic product):
for flt in data:
print('is nan {}'.format(npy.isnan(flt)))
slice of data
2006 3.89552e+11
2007 4.25065e+11
...
2014 4.63903e+11
2015 NaN
For the cell in question (the 2015 GDP), the code returns, which is what I expect:
is nan True
However, when I attempt to return a boolean series, like the replicated code, bullet 1 above, I get:
2006 False
2007 False
...
2014 False
2015 False
where 2015 should be True, based on the slice of data's 2015 NaN value.
Final comments, after getting the inconsistent results, even though it's automatically assigned when reading the file into a pandas.DataFrame, in an alternative attempt to isolate the problem, I assigned npy.nan to the cell in question through the DataFrame. The results, just mentioned, are the same.
Please help. :-)