API: Meta-issue for making consistent API's to refer to column names and index names
See original GitHub issueI would like to propose that any pandas API that allows specification of a column name also works when specifying an index level name. Today, this works in some places, but not all. Here is a list of places where things work, and where things don’t work and could be improved. (The list is most likely incomplete, so additions are welcome). References to existing issues are given when they already exist (and if I knew about them):
Hoping to include this in the roadmap #27478
Things that work:
DataFrame.query()
allows queries to use column names and index level namesDataFrame.merge()
andpd.merge()
allow both column names and index level names to be specified as key fields to use in the merge (but see below)DataFrame.groupby()
allows both column names and index level names to be mixed in the groupby list
Things that could be improved:
- Allow
.loc()
and.getitem()
to specify index level names wherever it allows column names. - Modify
DataFrame.rename()
to allow renaming of index levels with a dict argument. (#20421) - Allow index names to be specified like columns in
pd.Grouper()
(#19542) - When merging on a subset of
MultiIndex
levels, preserve the levels not included in the merge. (#13371 is somewhat related) - Have
.itertuples()
return a named tuple that includes index names (#27407) - Allow
.assign
to refer to columns that correspond to level names (although the.loc
and.getitem()
suggestion above might handle this
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:10 (9 by maintainers)
Top Results From Across the Web
What does it really mean to design a 'consistent' API?
Let's take an example — If there is an API field which is denoted by a plural field name and contains array or...
Read more >Metadata API - Developer Guide | Analytics Metadata API
The Metadata API returns the list of columns (i.e., dimensions and metrics) exposed in the Google Analytics reporting APIs and their attributes.
Read more >Jira Server platform REST API reference - Atlassian
Looking for the REST API reference for a different Jira version? ... Currently there are two API names available, which will be discussed...
Read more >Naming conventions | Cloud APIs
Product names refer to the product marketing names of APIs, such as Google Calendar API. Product names must be consistently used by APIs,...
Read more >Be consistent in setup of objects with column name for ...
Same applies with the column Indexed. It would be really neat, if the columns of the Standard Fields list and the Custom Fields...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, thanks @Dr-Irv . That narrows the gap, though not all the way: being able to specify the indexes without the context of the current indexes would be more declarative and clearer, particularly to a reader of the code.
As someone who is a heavy user of Multiindexes, I couldn’t agree more that this would be very useful to have. I find working in a fairly complex production codebase that whether a particular “column” is a best thought of as an index or a column in its own right is constantly switching back and forth, and so my code ends up being littered with reset_index() calls and set_index() calls.