Issue
im using pandas with excel and i would like to get the letter of the header in excel searching for column name.
here´s an example
i would like to do something LIKE this: df.columns.get_loc("SR Status") and i would like to return: "D"
i have already done this:
import pandas
df = pd.read_excel("file.xls")
df.columns.get_loc("SR Status")
and let´s assume data will NOT always be in the same place. sometimes it might be at header "A" but other time could be on other place thanks in advance
Solution
You can use get_column_letter
:
import pandas as pd
from openpyxl.utils import get_column_letter
df = pd.read_excel('data.xlsx', usecols='D:F')
offset = 4 # D
col = get_column_letter(df.columns.get_loc('SR Status') + offset)
print(col) # Output: D
Answered By - Corralien
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.