Python Pandas DataFrame with only a single number stored?

試著忘記壹切 提交于 2019-12-08 08:56:05

问题


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?


回答1:


Following code should work:

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



回答2:


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.



来源:https://stackoverflow.com/questions/44409066/python-pandas-dataframe-with-only-a-single-number-stored

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!