Closed
Description
Today I discovered a strange behaviour when iterating over groups where the group name contains a nan. Take the following data frame and group it. As expected there are two groups:
In [1]: df = pd.DataFrame([['a', 1, 1], ['b', sp.nan, 2]], columns = ['a', 'b', 'c'])
In [2]: grouped = df.groupby(['a', 'b'])
In [3]: print grouped.groups
{('a', 1.0): [0], ('b', nan): [1]}
Now, if I iterate over the groups the second group is missing:
In [4]: for name, group in grouped:
...: print name
('a', 1.0)
I would expect that the iteration works like this:
In [5]: for name, group in grouped.groups.items():
...: print name
('a', 1.0)
('b', nan)
pandas version:
In [6]: pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 2.7.6.final.0
python-bits: 64
OS: Linux
OS-release: 3.13.0-55-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
pandas: 0.15.2
nose: 1.3.1
Cython: 0.20.1post0
numpy: 1.9.1
scipy: 0.13.3
statsmodels: 0.5.0
IPython: 3.2.0
sphinx: None
patsy: 0.3.0
dateutil: 2.4.0
pytz: 2014.10
bottleneck: None
tables: 3.1.1
numexpr: 2.2.2
matplotlib: 1.3.1
openpyxl: 1.7.0
xlrd: 0.9.2
xlwt: 0.7.5
xlsxwriter: None
lxml: 3.3.3
bs4: 4.2.1
html5lib: 0.999
httplib2: 0.8
apiclient: None
rpy2: 2.3.9
sqlalchemy: 0.8.4
pymysql: None
psycopg2: 2.4.5 (dt dec mx pq3 ext)