pandas.read_excel() 仅将 excel sheet 的第一行作为数据框标签传递
pandas.read_excel() is only passing the first line of the excel sheet as a dataframe label
我正在尝试使用 pandas.read_excel() 读取 Excel 文件。该函数只获取我传递的 sheet 的第一行,它返回一个 0 x 1 数据帧。它不仅只占用第一行,而且还将其设置为数据框标签。我尝试将路径作为句柄传递,但结果相同
def read_excel_report(path):
try:
#handle = open(path)
dictionary
# representing a different worksheet.
raw_excel = pd.read_excel(path, sheet_name=-1, engine='openpyxl')
raw_excel = raw_excel.fillna('')
print("data extracted")
return raw_excel
except Exception as e:
print(e)
旧版本的 Pandas 会发生这种情况,其中 Excel 文件未正确创建。
最佳解决方案 是将您的 Python 版本升级到 3.8(或更高版本),将 Pandas 版本升级到 1.2(或更高版本)。这里有Pandaschangelog供大家参考。
如果这不可行,则解决方法是打开和关闭工作簿。即在使用 Pandas 的 read_excel
方法之前使用 openpyxl
库方法 load_workbook
和 close
。这会起作用,但会增加几秒钟的延迟。
我正在尝试使用 pandas.read_excel() 读取 Excel 文件。该函数只获取我传递的 sheet 的第一行,它返回一个 0 x 1 数据帧。它不仅只占用第一行,而且还将其设置为数据框标签。我尝试将路径作为句柄传递,但结果相同
def read_excel_report(path):
try:
#handle = open(path)
dictionary
# representing a different worksheet.
raw_excel = pd.read_excel(path, sheet_name=-1, engine='openpyxl')
raw_excel = raw_excel.fillna('')
print("data extracted")
return raw_excel
except Exception as e:
print(e)
旧版本的 Pandas 会发生这种情况,其中 Excel 文件未正确创建。
最佳解决方案 是将您的 Python 版本升级到 3.8(或更高版本),将 Pandas 版本升级到 1.2(或更高版本)。这里有Pandaschangelog供大家参考。
如果这不可行,则解决方法是打开和关闭工作簿。即在使用 Pandas 的 read_excel
方法之前使用 openpyxl
库方法 load_workbook
和 close
。这会起作用,但会增加几秒钟的延迟。