pandas.read_excel parameter “sheet_name” not working

后端 未结 4 1887
-上瘾入骨i
-上瘾入骨i 2021-02-13 14:21

According to the doc, pandas.read_excel has a parameter sheet_name that allows specifying which sheet is read. But when I am trying to read the second

相关标签:
4条回答
  • 2021-02-13 15:04

    You can try to use pd.ExcelFile:

    xls = pd.ExcelFile('path_to_file.xls')
    df1 = pd.read_excel(xls, 'Sheet1')
    df2 = pd.read_excel(xls, 'Sheet2')
    
    0 讨论(0)
  • 2021-02-13 15:15

    Try at Terminal, type the following first, then re-run your program: pip install xlrd

    0 讨论(0)
  • 2021-02-13 15:22

    It looks like you're using the old version of Python. So try to change your code

    df = pd.read_excel(file_with_data, sheetname=sheet_with_data)
    

    It should work properly.

    0 讨论(0)
  • 2021-02-13 15:24

    This works:

    df = pd.read_excel(open(file_path_name), 'rb'), sheetname = sheet_name)
    
    file_path_name = your file
    sheet_name = your sheet name
    

    This does not for me:

    df = pd.read_excel(open(file_path_name), 'rb'), sheet_name = sheet_name)
    

    Gave me only the first sheet, no matter how I defined sheet_name.

    --> it is an known error: https://github.com/pandas-dev/pandas/issues/17107

    0 讨论(0)
提交回复
热议问题