Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read in excel from column AF and onwards

How could I read an Excel file from column AF and onwards? I don't know the last column letter name and the file is too large to constantly keep checking.

df = pd.read_excel(r"Documents\file.xlsx", usecols="AF:")
like image 809
asd Avatar asked Sep 20 '25 07:09

asd


1 Answers

You can't write it directly in read_excel function so we can only look for other possible options.

For the moment we could write 'AF:XFD' because 'XFD' is the last column in excel, but it returns information that it will be depracated soon and start returning ParseError, so it's not recommended.

You can use other libraries to find the last column, but it doesn't work too fast - excel file is read, then we check last column and after that we create a dataframe.

If I had such problem I would do everything in Pandas, by adding .iloc at the end. We know that 'AF' is 32th column in excel, so:

df = pd.read_excel(r"Documents\file.xlsx").iloc[:, 32:]

It will return all columns from 'AF' till the end without having a noticeable impact on performance.

like image 86
Arkadiusz Avatar answered Sep 22 '25 21:09

Arkadiusz