gpt4 book ai didi

python - 如何从 HDInsight 群集下载从 pd.to_csv() 保存的文件

转载 作者:行者123 更新时间:2023-12-03 21:34:44 26 4
gpt4 key购买 nike

我有一个运行 Spark 1.6.2 和 Jupyter 的 HDInsight 集群在 jupyter 笔记本中,我运行 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')

我希望它保存在与我的笔记本相同的目录中,从而在浏览器的 TreeView 中看到它。不是这种情况。所以我的问题是:这个文件保存在文件系统上的什么位置?

<强>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 存储客户端库的版本引起的。对于旧版本,该库不包含您在代码中调用的方法。以下网址对您有用。

How to import Azure BlobService in python? .

关于python - 如何从 HDInsight 群集下载从 pd.to_csv() 保存的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39877341/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com