Skip to content
Advertisement

Python Pandas dataframe reading exact specified range in an excel sheet

I have a lot of different table (and other unstructured data in an excel sheet) .. I need to create a dataframe out of range ‘A3:D20’ from ‘Sheet2’ of Excel sheet ‘data’.

All examples that I come across drilldown up to sheet level, but not how to pick it from an exact range.

JavaScript

Once I get this, I plan to look up data in column A and find its corresponding value in column B.

Edit 1: I realised that openpyxl takes too long, and so have changed that to pandas.read_excel('data.xlsx','Sheet2') instead, and it is much faster at that stage at least.

Edit 2: For the time being, I have put my data in just one sheet and:

  • removed all other info
  • added column names,
  • applied index_col on my leftmost column
  • then used wb.loc[]

Advertisement

Answer

One way to do this is to use the openpyxl module.

Here’s an example:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement