【发布时间】:2017-02-14 02:20:47
【问题描述】:
我有一个运行 Spark 1.6.2 和 Jupyter 的 HDInsight 群集 在一个 jupyter notebook 中,我运行我的 pyspark 命令,一些输出在 pandas 数据帧中处理。
作为最后一步,我想将我的 pandas 数据框保存到一个 csv 文件中,并且:
- 将其保存到“jupyter 文件系统”并下载到我的笔记本电脑上
- 将其保存到我的 Blob 存储中
但我不知道该怎么做。
我尝试了以下方法:
1.将其保存到“jupyter 文件系统”并下载到我的笔记本电脑
# df is my resulting dataframe, so I save it to the filesystem where jupyter runs
df.to_csv('app_keys.txt')
我希望它保存在与我的笔记本相同的目录中,因此可以在浏览器的树视图中看到它。不是这种情况。所以我的问题是:这个文件保存在文件系统的什么位置?
2。将其保存到我的 Blob 存储中 谷歌搜索后,我似乎还可以使用 azure.storage.blob 模块将文件上传到 blob 存储。所以我尝试了:
from azure.storage.blob import BlobService # a lot of examples online import BlockBlobService but this one is not available in HDInsight
# i have all variables in CAPITALS provided in the code
blob_service=BlobService(account_name=STORAGEACCOUNTNAME,account_key=STORAGEACCOUNTKEY)
# check if reading from blob works
blob_service.get_blob_to_path(CONTAINERNAME, 'iris.txt', 'mylocalfile.txt') # this works
# now try to reverse the process and write to blob
blob_service.create_blob_from_path(CONTAINERNAME,'myblobfile.txt','mylocalfile.txt') # fails with AttributeError: 'BlobService' object has no attribute 'create_blob_from_path'
或
blob_service.create_blob_from_text(CONTAINERNAME,'myblobfile.txt','mylocalfile.txt') # fails with 'BlobService' object has no attribute 'create_blob_from_text'
所以我不知道如何回写并访问我从 pandas 写出的内容到文件系统。
感谢任何帮助
【问题讨论】:
标签: python azure pandas azure-blob-storage