错误:
FutureWarning: Passing bytes to 'read_excel' is deprecated and will be removed in a future version. To read from a byte string, wrap it in a `BytesIO` object.
df = pd.read_excel(blob_data.readall(), engine='openpyxl')
我收到此错误,还有其他选项可以从 Excel 文件读取数据吗?
我想要这个 openpyxl 问题的替代解决方案或库支持!
blob_data.readall()
是字节,不推荐将字节传递给 pandas.read_excel
。
您可以使用
BytesIO
: 传递类似文件的对象而不是字节
from io import BytesIO
import pandas as pd
df = pd.read_excel(BytesIO(blob_data.readall()), engine='openpyxl')
您将字节数据包装在
BytesIO
对象中,该对象的作用类似于类似文件的对象,并且可以与 read_excel
一起使用,而不会触发弃用警告。
import pandas as pd
from io import BytesIO
# Assuming blob_data is a bytes object containing the Excel file content
df = pd.read_excel(BytesIO(blob_data), engine='openpyxl')