如何从python脚本返回Azure ML中的Dataframe

时间:2017-01-11 08:46:42

标签: python web-services azure dataframe azure-machine-learning-studio

我有以下Python脚本。我正在尝试返回创建的新Dataframe。不幸的是,我收到了“NotImplementedError:”

请告诉我,如何从Python脚本中返回Azure ML中的Dataframe

代码:

def azureml_main(df) :

    therm_patterns,therm_missed_patterns = thermostat_phase(df)
    th_pat = json.loads(therm_patterns)
    missed_th_pat = json.loads(therm_missed_patterns)

    light_patterns, light_missed_patterns = light_phase(df)
    lt_pat = json.loads(light_patterns)
    missed_lt_pat = json.loads(light_missed_patterns)

    for j in range (0,len(lt_pat)):
        for i in range (0,len(lt_pat[0]['John'])):
            th_pat[0]['John'].append(lt_pat[0]['John'][i])
    for j in range (0,len(lt_pat)):
        for i in range (0,len(lt_pat[0]['Jane'])):
            th_pat[0]['Jane'].append(lt_pat[0]['Jane'][i])
    for j in range (0,len(lt_pat)):
        for i in range (0,len(lt_pat[0]['Jen'])):
            th_pat[0]['Jen'].append(lt_pat[0]['Jen'][i])

    for j in range (0,len(missed_lt_pat)):
        for i in range (0,len(missed_lt_pat[0]['John'])):
            missed_th_pat[0]['John'].append(missed_lt_pat[0]['John'][i])
    for j in range (0,len(missed_lt_pat)):
        for i in range (0,len(missed_lt_pat[0]['Jane'])):
            missed_th_pat[0]['Jane'].append(missed_lt_pat[0]['Jane'][i])
    for j in range (0,len(missed_lt_pat)):
        for i in range (0,len(missed_lt_pat[0]['Jen'])):
            missed_th_pat[0]['Jen'].append(missed_lt_pat[0]['Jen'][i])

    output = json.dumps(th_pat)

    df = pd.DataFrame.from_dict({k: v[0] for k, v in json.loads(output) 
    [0].items()}, 'index' ).rename_axis('User').reset_index()


    return df         

错误:

  Error 0085: The following error occurred during script evaluation, please  
  view the output log for more information:

   ---------- Start of error message from Python interpreter ----------
   Caught exception while executing function: Traceback (most recent call  
   last):

       File "C:\server\invokepy.py", line 211, in batch
       xdrutils.XDRUtils.DataFrameToRFile(outlist[i], outfiles[i], True)

       File "C:\server\XDRReader\xdrutils.py", line 54, in DataFrameToRFile
       xdrwriter.write_attribute_list(attributes)

       File "C:\server\XDRReader\xdrwriter2.py", line 155, in   
       write_attribute_list
       self.write_object(value)

       File "C:\server\XDRReader\xdrwriter2.py", line 215, in write_object
       write_func(flags, converted, missingIndices)

       File "C:\server\XDRReader\xdrwriter2.py", line 185, in write_objects
       self.write_object(value)

       File "C:\server\XDRReader\xdrwriter2.py", line 200, in write_object
       raise NotImplementedError('Python Bridge conversion table not    
       implemented for type [{0}]'.format(value.getType()))

       NotImplementedError: Python Bridge conversion table not implemented  
       for type [<type 'list'>]

       Process returned with non-zero exit code 1

2 个答案:

答案 0 :(得分:0)

最好的想法是将其作为CSV文件(azure python脚本中的geniune选项)返回,然后如果您愿意,可以将其转换回df。但我确实相信csv文件是你需要的最终产品

答案 1 :(得分:0)

看起来您的数据框包含元组作为列的值。截至目前,Azure机器学习工作区不支持数据框中的元组。