答案 0 :(得分:0)
听起来您想在Azure Machine Learning Studio的实验的Execute Python Script
模块中读取Excel文件。根据官方文档[Execute Python machine learning scripts in Azure Machine Learning Studio][1]
,有两种方法可以做到这一点。
要将Excel文件上传到Azure Blob存储,然后按照Accessing Azure Storage Blobs
节使用适用于Python的Azure Blob存储SDK进行阅读。
请参阅Importing existing Python script modules
部分,将Excel文件与其他必需的Python软件包打包为zip文件,然后通过自动提取从zip文件名为Script Bundle
的目录中读取它由Azure ML Stodio提供。
作为参考,我将向您显示第二种解决方案的详细步骤,如下所示。
我准备了一个名为test.xlsx
的Excel文件,其内容如下。
从其PyPi.org页面下载xlrd
软件包文件xlrd-1.2.0-py2.py3-none-any.whl
,然后将其压缩文件提取到目录test
中,并用{{1 }}到一个压缩文件test.xlsx
,如下所示。
我将zip文件test.zip
作为数据集上传到Azure ML Studio,并使用test.zip
模块进行了组装。
这是我的示例代码。我尝试将Execute Python Script
,os.getcwd()
,os.listdir()
与日志结合使用,以找到用于读取zip文件中文件的正确路径。
os.listdir('Script Bundle')
它在import pandas as pd
def azureml_main(dataframe1 = None, dataframe2 = None):
import os
print(os.getcwd())
print(os.listdir())
print(os.listdir('Script Bundle'))
import xlrd
file = 'Script Bundle/test.xlsx'
data = xlrd.open_workbook(file)
print([sheet.name for sheet in data.sheets()])
print('Input pandas.DataFrame #1:\r\n\r\n{0}'.format(dataframe1))
return dataframe1,
中起作用,日志如下。
希望有帮助。