![](/img/trans.png)
[英]Read xlsx from azure blob storage to pandas dataframe without creating temporary file
[英]How to read .xlsx format file from Azure Blob using pandas without creating temporary file
下面是我的代码。
from azure.storage.blob import BlobClient, BlobServiceClient
import pandas as pd
from io import StringIO
account_url = "XXXXXX"
containerName = "XXXXXX"
blob_name = 'Abc.xlsx'
storageKey = "XXXXX"
connection_string = "XXXX"
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
blob_client = blob_service_client.get_blob_client(container=containerName, blob=blob_name)
blob = blob_client.download_blob().content_as_text(encoding=None)
engine = 'xlrd'
df = pd.read_excel(io = blob, engine = engine)
当我运行它时,代码抛出异常:
raise ValueError('Must explicitly set engine if not passing in'
ValueError: Must explicitly set engine if not passing in buffer or path for io.
任何帮助,将不胜感激。
下面的代码使用内存中的流下载而不创建临时文件,pandas 从流中读取 excel。
from azure.storage.blob import BlobServiceClient
import pandas as pd
from io import BytesIO
containerName = "XXXX"
blob_name = 'Abc.xlsx'
connection_string = "XXXX"
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
blob_client = blob_service_client.get_blob_client(containerName, blob_name)
with BytesIO() as input_stream:
blob = blob_client.download_blob().download_to_stream(input_stream)
df = pd.read_excel(io=input_stream)
print(df)
data=pd.read_excel("C:\\ex1.xlsx") 或 data=pd.read_excel(r"C:\\ex1.xlsx") #如果你使用Windows,有时需要
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.