NaN keyed dictionaries for pandas series

I am trying to build a Pandas series by passing it a dictionary containing index and data pairs. In doing so, I noticed an interesting quirk. When a dictionary contains NaN keys with an associated value, Pandas Series stores the NaN key in the index, but also sets the corresponding NaN value.

import pandas as pd
d = {np.nan: 3500.0, 66485174.0: 1.0}
d = pd.Series(d, dtype='float64')

      

In the above example 3500.0 will be set to NaN using pd.Series. I am using Pandas 0.20.2 with python 2.7.

Does anyone know why this is happening? My intuition is that NaN is probably treated as an infinite number outside of 64-bit, so format issues may arise

+3
python dictionary python-2.7 pandas


source to share


No one has answered this question yet

Check out similar questions:

4268
How to combine two dictionaries in one expression?
3428
How to sort a dictionary by value?
2683
Check if the given key exists in the dictionary
2679
Iterating over dictionaries using 'for' loops
2391
What's the best way to iterate over a dictionary?
2369
Add new keys to the dictionary?
1687
How to sort a list of dictionaries by dictionary value?
1553
Renaming columns in pandas
1470
How do I remove a key from a Python dictionary?
1201
Remove item from dictionary



All Articles
Loading...
X
Show
Funny
Dev
Pics