Pandas read_excel() with multiple sheets and specific columns

前端 未结 1 569
[愿得一人]
[愿得一人] 2021-01-18 01:31

I\'m trying to use pandas.read_excel() to import multiple worksheets from a spreadsheet. If I do not specify the columns with the parse_cols keyword I\'m able

相关标签:
1条回答
  • 2021-01-18 02:21

    When you pass a list of sheet names to read_excel, it returns a dictionary. You can achieve the same thing with a loop:

    workSheets = ['sheet1', 'sheet2', 'sheet3', 'sheet4']
    cols = ['A,E', 'A,E', 'A,C', 'A,E']
    df = {}
    for ws, c in zip(workSheets, cols):
        df[ws] = pd.read_excel(excelFile, sheetname=ws, parse_cols=c)
    

    Below is update for Python 3.6.5 & Pandas 0.23.4:

    pd.read_excel(excelFile, sheet_name=ws, usecols=c)
    
    0 讨论(0)
提交回复
热议问题