BUG/API: bug in multi-index slicing with missing indexers · Issue #7866 · pandas-dev/pandas (original) (raw)
Navigation Menu
- GitHub Copilot Write better code with AI
- GitHub Models New Manage and compare prompts
- GitHub Advanced Security Find and fix vulnerabilities
- Actions Automate any workflow
- Codespaces Instant dev environments
- Issues Plan and track work
- Code Review Manage code changes
- Discussions Collaborate outside of code
- Code Search Find more, search less
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Description
I think the following could work and not raise KeyError
because of a missing indexer. This would follow the API of loc which will be effectively a reindex as long as you have at least 1 found value.
s = pd.Series(np.arange(9),index=pd.MultiIndex.from_product([['A','B','C'],['foo','bar','baz']],names=['one','two'])).sortlevel()
s.loc[['A','D']]
idx = pd.IndexSlice
s.loc[idx[:,['foo','bah']]]