1

I would like to select a specific range of cells in a workbook worksheet. I am currently able to set a variable to a workbook worksheet with the line below.

 import pandas as pd
 sheet1 = pd.read_excel('workbookname1.xlsx', sheet_name = ['sheet1'])

I would like to go one step further and have the ability to select a range of cells in the worksheet so that I can practice dataframe functionality with the defined range. Some of my ranges are with row values greater than 1000. How am I able to select a variable length row value for the desired excel range?

stovfl
  • 14,998
  • 7
  • 24
  • 51
SBF12345
  • 75
  • 1
  • 2
  • 10
  • Relevant [selecting-a-row-of-pandas-series-dataframe-by-integer-index](https://stackoverflow.com/questions/16096627/selecting-a-row-of-pandas-series-dataframe-by-integer-index/16104482#16104482) – stovfl Feb 23 '19 at 17:09

1 Answers1

3

You can utilize OpenPyXl module.

from openpyxl import Workbook, load_workbook

wb = load_workbook("workbookname1.xlsx")
ws = wb.active
cell_range = ws['A1':'C2']

You can also use iter_rows() or iter_columns() methods.

For additional information, you can refer to OpenPyXL documentation.

Patriots299
  • 365
  • 3
  • 15