Python Pandas dataframe reading exact specified range in an excel sheet

Use the following arguments from pandas read_excel documentation:

  • skiprows : list-like
    • Rows to skip at the beginning (0-indexed)
  • nrows: int, default None
    • Number of rows to parse.
  • parse_cols : int or list, default None
    • If None then parse all columns,
    • If int then indicates last column to be parsed
    • If list of ints then indicates list of column numbers to be parsed
    • If string then indicates comma separated list of column names and column ranges (e.g. “A:E” or “A,C,E:F”)

I imagine the call will look like:

df = read_excel(filename, 'Sheet2', skiprows = 2, nrows=18,  parse_cols="A:D")

EDIT:

in later version of pandas parse_cols has been renamed to usecols so the above call should be rewritten as:

df = read_excel(filename, 'Sheet2', skiprows = 2, nrows=18,  usecols="A:D")

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)