Skip to content

Large multiindex dataframe shows only NaN values after selected rows are dropped #12754

Closed
@sylvaticus

Description

@sylvaticus

NOTE: This issue has been already submitted to SO where the only person replying did replicate the behaviour in pandas 18.0.

Using the pandas library v. 17.1, I am trying to remove the rows from a large (882504 rows) dataframe named productDataNat where parName=='rt', but then all the other rows become NaN:

Code Sample, a copy-pastable example if possible

Importing and showing the multiaxis dataframe..

productDataNat = pd.read_csv('https://lobianco.org/temp/productData_P0-Mi-Ei.csv',sep=';',  dtype={'value': np.float64})
productDataNat = productDataNat.drop(['Unnamed: 8'],axis=1)
productDataNat.set_index(['scen','country','region','prod','freeDim','year','parName'], inplace=True)
productDataNat.head()

screenshot from 2016-03-25 14 26 00

Here I drop by same values in an internal axis.. all the remaning values are NaN!:
productDataNat.drop('rt', level='parName', axis=0)
screenshot from 2016-03-25 14 29 30

Expected Output

When instead I play with an example dataframe it works as expected:

midx = pd.MultiIndex(levels=[['one', 'two'], ['x','y']], labels=[[1,1,1,0],[1,0,1,0]])
dfmix = pd.DataFrame({'A' : [1, 2, 3, 4], 'B': [5, 6, 7, 8]}, index=midx)
dfmix

screenshot from 2016-03-25 14 32 51

dfmix.drop('x',level=1,axis=0)
screenshot from 2016-03-25 14 34 01

output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.4.3.final.0
python-bits: 64
OS: Linux
OS-release: 3.13.0-83-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.17.1
nose: 1.3.1
pip: 1.5.4
setuptools: 3.3
Cython: None
numpy: 1.10.4
scipy: 0.13.3
statsmodels: None
IPython: 4.0.0
sphinx: 1.2.2
patsy: None
dateutil: 2.5.0
pytz: 2015.7
blosc: None
bottleneck: 1.0.0
tables: None
numexpr: 2.5
matplotlib: 1.3.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999
httplib2: 0.8
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
Jinja2: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions