我如何从存储在Azure Blob存储与Azure机器学习工作室的多个文件读取数据"一次"?
我试图使用阅读器模块,它的工作只是一个文件很好,它可以为多个有用,或者我必须寻找其他解决方案吗?
感谢您的帮助
如果没有那么多blob,您可以为每个输入blob的映射添加多个读取器。然后使用"数据转换"->"操作"下的模块来做诸如"添加行"或"连接"之类的事情。
使用大量读取器从不同的blob中读取,然后将它们连接到元数据编辑器
虽然使用多个Reader
模块的方法可以工作,但当有许多输入或输入数量变化时,它变得非常困难。
相反,可以使用Execute Python Script
模块直接访问blob存储。然而,如果你以前从未这样做过,那么这样做是非常痛苦的。以下是问题:
-
azure.storage.blob
Python包默认不加载到Azure ML中。但是,可以手动创建,或者从下面的链接下载(2016年2月11日的正确版本)。 -
azure.storage.blob.BlobService
的默认用法使用HTTPS,目前在Azure ML blob存储访问中不支持。为此,您可以在创建BlobService期间传入protocol='http'
,以强制使用HTTP:client = BlobService(STORAGE_ACCOUNT, STORAGE_KEY, protocol="http")
下面是使它工作的步骤:
- 下载
azure.zip
,它提供了所需的azure.storage.*
库:https://azuremlpackagesupport.blob.core.windows.net/python/azure.zip - 将它们作为数据集上传到Azure ML Studio
- 连接到
Execute Python Script
模块的Zip输入,这是第三个输入。 - 像往常一样编写脚本,确保用
protocol='http'
创建BlobService
对象 - 运行实验-你现在应该能够读写blob存储
可以在这里找到一些示例代码:https://gist.github.com/drdarshan/92fff2a12ad9946892df
下面是使它为单个文件工作的代码。通过访问容器和过滤,可以将其扩展为处理许多文件,但这将取决于您的业务逻辑。
from azure.storage.blob import BlobService
def azureml_main(dataframe1 = None, dataframe2 = None):
account_name = 'mystorageaccount'
account_key='p8kSy3FACx...redacted...ebz3plQ=='
container_name = "upload"
blob_service = BlobService(account_name, account_key, protocol='http')
file = blob_service.get_blob_to_text(container_name,'myfile.txt')
# You can also get_blob_to_(bytes|file|path), if you need to do so.
# Do stuff with your file here
# Logic, logic, logic
# Execute Python Script requires that a dataframe is returned. It can be null.
# Return value must be of a sequence of pandas.DataFrame
return dataframe1,
有关限制的更多信息,为什么使用HTTP,以及其他注意事项,请参见从Azure ML实验中访问Azure博客存储