Msquare
Msquare

Reputation: 835

How to import specific columns and rows from Excel using Pandas

My excel has many columns and rows data. But I want to import specific columns and rows data.

My code:

L_pos_org = pd.read_excel('EXCELFILE.xlsx',sheet_name='Sheet1',na_values=['NA'],usecols = "M:U")

Above code extract the columns that I want but it also extracts all rows.

enter image description here

In above excel file, I am trying to extract the data of Columns M:U and rows 106:114.

How to extract this?

Upvotes: 3

Views: 8803

Answers (1)

Evan VanderZee
Evan VanderZee

Reputation: 867

Looking at the documentation here, it seems that with a recent enough version of Pandas you could extract a specific block of rows using the parameters skiprows and nrows. I think the command would look something like

pd.read_excel('EXCELFILE.xlsx',sheet_name='Sheet1',header=None,na_values=['NA'],usecols="M:U",skiprows=range(105),nrows=9)

Upvotes: 2

Related Questions