Skip to content

unexpected behavior with NaN in multiIndex  #15107

Closed
@micheledemeo

Description

@micheledemeo
df = pd.DataFrame({'col':[1, 2, 3, 4, 5], 'ind1':['a','b','c','d',np.nan], 'ind2':[1,2,3,4,5] })
df.set_index(['ind1','ind2'],inplace=True)

df.loc['a']
#     col
# ind2
# 1     1

df.loc[['a']]
#            col
# ind1 ind2
# a    1       1
#      5       5

df.loc[['a']].reset_index()
#   ind1  ind2  col
# 0    a     1    1
# 1    a     5    5

Problem description

Is it normal replacing np.nan with 'a' ?

INSTALLED VERSIONS ------------------ commit: None python: 2.7.5.final.0 python-bits: 64 OS: Linux OS-release: 3.10.0-327.28.3.el7.x86_64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8

pandas: 0.19.2
nose: None
pip: 9.0.1
setuptools: 32.0.0
Cython: None
numpy: 1.11.3
scipy: 0.18.1
statsmodels: None
xarray: None
IPython: 5.1.0
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.5.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    IndexingRelated to indexing on series/frames, not to indexes themselvesMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolateMultiIndex

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions