I need to read multiple tables from a sheet in an Excel file with python. The sheet looks something like this:
I want to get a python object containing the information in First_Table and the same for Second_Table. I tried using pandas and Dataframe.iloc this way:
import pandas as pd
xls = pd.ExcelFile('path_to_xls_file')
df = pd.read_excel(xls, "sheet_1")
# first table
df1 = df.iloc[2:12,0:6]
But I didn't get the expected cells from the First_Table. Am I doing something wrong with the ranges of the rows and columns? Does it have to be specified with the exact row and col indices or is there a more efficient and elegant way to do it?
Thanks in advance!
Use "usecols" argument to select the columns you want to read from excel file. Pandas will select the rows accordingly.
Also you need to set index to False to avoid getting first column as index.
Following is the example code for your task
pd.read_excel(path, usecols=range(1,6), index=False)
Find more information in documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With