-2

i have one workbook with 53 worksheets in excel. I want to get all the data from the sheets, but i need only the data in particular rows and columns. The data structure in workbook is the same in all sheets.

The structure is something like this:

Excel workbook

  • 1
    Hi, you should do some level of research. Simply search "python read excel", you would find a lot of questions related – ZisIsNotZis Dec 12 '18 at 07:02

1 Answers1

0

You can use pandas:

import pandas as pd


# Read multiple sheets from one workbook
with pd.ExcelFile('path_to_file.xlsx') as xlsx:
    df1 = pd.read_excel(xlsx, 'Sheet1')
    df2 = pd.read_excel(xlsx, 'Sheet2')

    # Work with specific columns
    df1[['Column1', 'Column2']] # Do something with these
    df1[['Column1', 'Column2']] # Do something with these
  • Are these empty rows 1) between rows that contain data or 2) are they at the end of the file? If 1), then you could delete them following [this answer](https://stackoverflow.com/a/25146613/5535114). If 2), then you should better delete them from within the excel file itself. – Edgar Ramírez Mondragón Dec 12 '18 at 07:35
  • Thanks for your help sir. I change a little bit the code like this: df1 = pd.read_excel(xlsx, sheet_name='Page2', skiprows=1, header=None, usecols='F:I') and it works fine. The empty rows look like this: 13 HIKVISION DS-2CE56C0T-IRF € 18 NaN 17 NaN NaN NaN NaN 18 HIKVISION DS-2CE56C0T-IT3F € 28 NaN 19 NaN NaN NaN NaN – Denis Dragnev Dec 12 '18 at 07:39
  • If this answer was helpful, please consider upvoting :) – Edgar Ramírez Mondragón Dec 12 '18 at 07:40