【发布时间】:2019-06-10 05:25:07
【问题描述】:
我有一个 pandas 数据框,想将它作为 parquet 文件写入 Azure 文件存储。
到目前为止,我还无法将数据帧直接转换为字节,然后我可以将其上传到 Azure。 我目前的解决方法是将其作为 parquet 文件保存到本地驱动器,然后将其作为字节对象读取,我可以将其上传到 Azure。
谁能告诉我如何将 pandas 数据帧直接转换为“parquet 文件”字节对象而不将其写入磁盘? I/O 操作真的让事情变慢了,感觉很像非常丑陋的代码......
# Transform the data_frame into a parquet file on the local drive
data_frame.to_parquet('temp_p.parquet', engine='auto', compression='snappy')
# Read the parquet file as bytes.
with open("temp_p.parquet", mode='rb') as f:
fileContent = f.read()
# Upload the bytes object to Azure
service.create_file_from_bytes(share_name, file_path, file_name, fileContent, index=0, count=len(fileContent))
我正在寻求实现类似的东西,其中 transform_functionality 返回一个字节对象:
my_bytes = data_frame.transform_functionality()
service.create_file_from_bytes(share_name, file_path, file_name, my_bytes, index=0, count=len(my_bytes))
【问题讨论】:
标签: python pandas azure pyarrow