2

AzureML's Python Script module requires to return a Pandas DataFrame. I want to return only a value and I do this:

result=7
dataframe1=pd.DataFrame(numpy.zeros(1))
dataframe1[0][0]=result

by which I am able to return just a single value in Azure ML's Python Script module.

What is a proper way to create a pandas DataFrame with a single value?

hhh
  • 47,778
  • 59
  • 172
  • 269
  • 1
    the minimum would be `pd.DataFrame([result])` – EdChum Jun 07 '17 at 09:46
  • @EdChum I tried that but it did not work in Azure ML, it complained something about the wrong type as a return type. – hhh Jun 07 '17 at 09:52
  • 1
    Well the only different here is that your version produces a df with dtype float, my snippet would preserve the result as `int`, does AzureML require floats? If so you can do `pd.DataFrame([result], dtype=float)` – EdChum Jun 07 '17 at 09:54
  • @EdChum thank you, I tested it and it works! – hhh Jun 07 '17 at 10:05

2 Answers2

1

As EdChum commented

dataframe1=pd.DataFrame([result], dtype=float) 

and it works, tested, instead of

result=7
dataframe1=pd.DataFrame(numpy.zeros(1))
dataframe1[0][0]=result

where we don't need to use numpy to initiate the return value with zeroes.

P.s. EdChum can make this his answer if he wants.

hhh
  • 47,778
  • 59
  • 172
  • 269
  • 1
    No need to make additional work for SO, just remember to accept your own answer so the question doesn't remain unanswered, seems odd to me that the dtype must be float but then I've never used azureML +1 – EdChum Jun 07 '17 at 10:10
1

Following code should work:

import pandas as pd
def azureml_main(dataframe1 = None, dataframe2 = None):
    result = pd.DataFrame({'mycol': [123]})
    return result,