A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pandas-dev/pandas/issues/35132 below:

Passing `level=` to `DataFrame.reindex` fails when the index is flat · Issue #35132 · pandas-dev/pandas · GitHub

Code Sample, a copy-pastable example
import numpy as np
import pandas as pd

df = pd.DataFrame(np.random.randn(100,40), index=pd.Index(np.arange(100), name='foo'))
new_index = pd.Index(np.arange(50), name='foo')
df.reindex(new_index, level='foo')
Problem description

Currently the above raises AttributeError: 'Int64Index' object has no attribute 'levels'.

The behavior of DataFrame.reindex should be consistent between flat Indexes and MultiIndexes - as long the level is valid, I shouldn't have to check whether the index is a flat index or a MultiIndex before deciding whether to pass level=.

Expected Output

Same as df.reindex(new_index)

Output of pd.show_versions() INSTALLED VERSIONS

commit : None
python : 3.7.6.final.0
python-bits : 64
OS : Linux
OS-release : 5.3.0-53-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.0.5
numpy : 1.18.4
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 47.3.1.post20200622
Cython : 0.29.19
pytest : None
hypothesis : None
sphinx : 3.1.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.4.1
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.15.0
pandas_datareader: None
bs4 : 4.9.0
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.4.1
matplotlib : 3.1.3
numexpr : 2.7.1
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : 3.4.4
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None
numba : 0.48.0


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4