Skip to content
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

ENH: support using letters as column names in read_excel #54552

Closed
1 of 3 tasks
wangxiya opened this issue Aug 15, 2023 · 7 comments
Closed
1 of 3 tasks

ENH: support using letters as column names in read_excel #54552

wangxiya opened this issue Aug 15, 2023 · 7 comments
Labels
Closing Candidate May be closeable, needs more eyeballs Enhancement IO Excel read_excel, to_excel Needs Discussion Requires discussion from core team before further action

Comments

@wangxiya
Copy link

wangxiya commented Aug 15, 2023

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

目前,如果head=None,则dataframe的column为1,2,3,4,……

Currently, if header=None, the column names are "1, 2, 3, 4, ......" by default.

Feature Description

建议加入一个参数,在head=None时,可以将dataframe的column设置A,B,C,D,……

Add another parameter so that when header=None, users can set the column name to "A, B, C, D, ......"

Alternative Solutions

None

Additional Context

No response

@wangxiya wangxiya added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 15, 2023
@fangchenli fangchenli changed the title ENH: 建议在read_excel方法中,可以支持将excel的字母列作为names ENH: support using letters as column names in read_excel Aug 15, 2023
@fangchenli fangchenli added the IO Excel read_excel, to_excel label Aug 15, 2023
@fangchenli
Copy link
Member

fangchenli commented Aug 15, 2023

I added the English translation.

@fangchenli
Copy link
Member

Use the names parameter?

@fangchenli fangchenli removed the Needs Triage Issue that has not been reviewed by a pandas team member label Aug 15, 2023
@wangxiya
Copy link
Author

使用names参数可以实现,我也是这么做的。但似乎可以更简便一点。因为excel使用A,B,...Z,AA,AB...是更常见的方法。比如names=letter,read_excel就自动将列索引从1,2,3...,改为A,B,C...

@rmhowe425
Copy link
Contributor

@rhshadrach Does this issue require further discussion or can I work on creating a PR?

@rhshadrach
Copy link
Member

@rmhowe425 - what do you think proper resolution of this issue would entail?

@rhshadrach rhshadrach added the Needs Discussion Requires discussion from core team before further action label Sep 7, 2023
@rhshadrach
Copy link
Member

I'm currently -1 here, users are able to do this via:

def number_to_excel_name(idx):
    if idx < 0:
        raise ValueError("Index must be nonnegative")
    result = ""
    while idx > -1:
        idx, r = divmod(idx, 26)
        result = chr(r + ord('A')) + result
        idx -= 1
    return result


df = pd.DataFrame(columns=range(0, 100))
df.columns = [number_to_excel_name(idx) for idx in df.columns]

@rhshadrach rhshadrach added the Closing Candidate May be closeable, needs more eyeballs label Oct 13, 2023
@phofl
Copy link
Member

phofl commented Dec 8, 2023

agree with @rhshadrach here, closing

@phofl phofl closed this as completed Dec 8, 2023
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 Enhancement IO Excel read_excel, to_excel Needs Discussion Requires discussion from core team before further action
Projects
None yet
Development

No branches or pull requests

5 participants