【问题标题】:How to download my file from HDInsight cluster that is saved from pd.to_csv()如何从从 pd.to_csv() 保存的 HDInsight 群集下载我的文件
【发布时间】:2017-02-14 02:20:47
【问题描述】:

我有一个运行 Spark 1.6.2 和 Jupyter 的 HDInsight 群集 在一个 jupyter notebook 中,我运行我的 pyspark 命令,一些输出在 pandas 数据帧中处理。

作为最后一步,我想将我的 pandas 数据框保存到一个 csv 文件中,并且:

  1. 将其保存到“jupyter 文件系统”并下载到我的笔记本电脑上
  2. 将其保存到我的 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


    【解决方案1】:

    根据我的经验,您遇到的第二个问题是由于用于 python 的 azure 存储客户端库的版本。 对于旧版本,该库不包含您在代码中调用的方法。以下网址对您很有用。

    How to import Azure BlobService in python?.

    【讨论】:

    • 谢谢...我确实在 0.20 上,这是 azure hd 洞察集群中的默认版本。在集群中升级它的最简单方法是什么? SSH 进入每台机器并执行 pip install blob-storage --upgrade ?
    • 你提到的方法可能是最简单有用的方法。
    猜你喜欢
    • 2013-06-20
    • 2021-10-22
    • 1970-01-01
    • 1970-01-01
    • 2019-02-22
    • 1970-01-01
    • 2018-05-29
    • 1970-01-01
    • 2016-06-02
    相关资源
    最近更新 更多