We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import pandas as pd raw_data = {'regiment': ['Nighthawks', 'Nighthawks', 'Nighthawks', 'Nighthawks', 'Dragoons', 'Dragoons', 'Dragoons', 'Dragoons', 'Scouts', 'Scouts', 'Scouts', 'Scouts'], 'company': ['1st', '1st', '2nd', '2nd', '1st', '1st', '2nd', '2nd', '1st', '1st', '2nd', '2nd'], 'name': ['Miller', 'Jacobson', 'Ali', 'Milner', 'Cooze', 'Jacon', 'Ryaner', 'Sone', 'Sloan', 'Piger', 'Riani', 'Ali'], 'preTestScore': [4, 24, 31, 2, 3, 4, 24, 31, 2, 3, 2, 3], 'postTestScore': [25, 94, 57, 62, 70, 25, 94, 57, 62, 70, 62, 70]} df = pd.DataFrame(raw_data, columns = ['regiment', 'company', 'name', 'preTestScore', 'postTestScore']) df_gbm = df.groupby(['regiment', 'company']).mean() df_gbm_preTS_gt10 = df_gbm[df_gbm.preTestScore > 10] df_gbm_preTS_gt10.index.levels[0].tolist() df_gbm_preTS_gt10.index.get_level_values(0).unique().tolist()
I was expecting MultiIndex.levels[0].tolist() to give the same results as MultiIndex.get_level_values(0).unique().tolist() but that is not the case.
MultiIndex.levels[0].tolist()
MultiIndex.get_level_values(0).unique().tolist()
df_gbm_preTS_gt10
df_gbm_preTS_gt10.index.levels[0].tolist() ['Dragoons', 'Nighthawks', 'Scouts'] df_gbm_preTS_gt10.index.get_level_values(0).unique().tolist() ['Dragoons', 'Nighthawks']
df_gbm_preTS_gt10.index.levels[0].tolist() ['Dragoons', 'Nighthawks']
pd.show_versions()
commit: None python: 3.6.1.final.0 python-bits: 64 OS: Linux OS-release: 4.10.0-20-generic 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: 27.2.0 Cython: None numpy: 1.12.1 scipy: 0.19.0 statsmodels: None xarray: None IPython: 6.0.0 sphinx: None patsy: None dateutil: 2.6.0 pytz: 2017.2 blosc: None bottleneck: None tables: None numexpr: None matplotlib: 2.0.0 openpyxl: None xlrd: None xlwt: None xlsxwriter: None lxml: None bs4: None html5lib: 0.999 httplib2: None apiclient: None sqlalchemy: None pymysql: None psycopg2: None jinja2: 2.9.6 boto: None pandas_datareader: None
The text was updated successfully, but these errors were encountered:
you have unobserved levels which persist thru indexing
see http://pandas-docs.github.io/pandas-docs-travis/generated/pandas.MultiIndex.remove_unused_levels.html?highlight=remove_unused#pandas.MultiIndex.remove_unused_levels
and the original issue: #2770
Sorry, something went wrong.
OK, thanks. Should I make a PR for documenting this? Because this is the entry for pandas.MultiIndex.levels in the API documentation:
pandas.MultiIndex.levels
additional documentation is always welcome!
No branches or pull requests
Code Sample, a copy-pastable example if possible
Problem description
I was expecting
MultiIndex.levels[0].tolist()
to give the same results asMultiIndex.get_level_values(0).unique().tolist()
but that is not the case.df_gbm_preTS_gt10
Expected Output
Output of
pd.show_versions()
commit: None
python: 3.6.1.final.0
python-bits: 64
OS: Linux
OS-release: 4.10.0-20-generic
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: 27.2.0
Cython: None
numpy: 1.12.1
scipy: 0.19.0
statsmodels: None
xarray: None
IPython: 6.0.0
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 2.0.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.6
boto: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: