Skip to content

ENH: column nicknames or shorthands #55060

New issue

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

Closed
1 of 3 tasks
tennlee opened this issue Sep 8, 2023 · 6 comments
Closed
1 of 3 tasks

ENH: column nicknames or shorthands #55060

tennlee opened this issue Sep 8, 2023 · 6 comments
Labels
Closing Candidate May be closeable, needs more eyeballs metadata _metadata, .attrs Usage Question

Comments

@tennlee
Copy link

tennlee commented Sep 8, 2023

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

I often load data with complex column names. For example, in the source data, the column name might be "temp: method one" or some other longish string. I don't necessarily want to lose these complex names, but they are not convenient to use when indexing into data. The current options appear to be to rename the columns to something more convenient, to use numerical indexing, or to create a dictionary which will map from a shorthand string to the full column name.

Feature Description

Add a new method to a DataFrame to specify an alternative set of column names which would then be used by indexing methods if set.

e.g.

df.columns_nicknames = ['tmp', 'value', 'timeofday']

Alternative Solutions

I don't have anything else in mind.

Additional Context

No response

@tennlee tennlee added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 8, 2023
@attack68
Copy link
Contributor

attack68 commented Sep 8, 2023

This has the same response as #54963 . I do not believe pandas should be responsible for dual labelled columns or any other form of short hand. Additional to that response pandas Styler also has relabel_index which handles displaying different labels but doesnt lose the indexing capability for the underlying dataframe. Examples are provided in the documentation.

@lithomas1
Copy link
Member

This might be a good usecase for attrs.

xref #42582

(you might want to try using the shorthand names but keeping the long name as an attr
https://pandas.pydata.org/docs/dev/reference/api/pandas.DataFrame.attrs.html)

@lithomas1 lithomas1 added Usage Question metadata _metadata, .attrs and removed Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 8, 2023
@rhshadrach
Copy link
Member

I think the complexity involved in maintaining a second set of names for columns is not worth the benefit.

@rhshadrach rhshadrach added the Closing Candidate May be closeable, needs more eyeballs label Sep 9, 2023
@jbrockmendel
Copy link
Member

There is an old issue about label aliases that I thought was interesting. The use case I had in mind was an index of US state names and doing lookups with abbreviations eg “CA”. I did something similar in a personal project 5ish years ago. IIRC I patched get_loc to do the alias lookup, stored the aliases on the index object. I doubt past-me dealt with get_indexer correctly or at all.

@tennlee
Copy link
Author

tennlee commented Sep 11, 2023

Thanks all for considering the idea - I realise it might not be important or worth the complexity, so thanks for giving it your attention thus far. I'm happy if you do just want to close the issue. I'm not sure whether to go ahead and close this myself, so I'll leave it to the discretion of the pandas team for now.

@lithomas1 makes an excellect suggestion which seems quite practical and doesn't require any new functionality, although I do note that this functionality is marked as experimental in the docs.

@mroeschke
Copy link
Member

Thanks for the suggestion but closing as the original proposal doesn't seem to have much support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closing Candidate May be closeable, needs more eyeballs metadata _metadata, .attrs Usage Question
Projects
None yet
Development

No branches or pull requests

6 participants