The same input is used in two cases, but the different result is returned from a python module.
import pandas as pd
import sys
def get_segments(dataframe):
dataframe['segment']=dataframe['segment'].astype('str')
segments = dataframe.loc[~dataframe['segment'].duplicated()]['segment']
return segments
def azureml_main(dataframe1 = None, dataframe2 = None):
df = dataframe1
segments = get_segments(df)
segmentCount =segments.size
if (segmentCount > 0) :
res = pd.DataFrame(columns=['segmentId','recommendation'],index=[range(segmentCount)])
i=0
for seg in segments:
d= df.query('segment ==["{}"]'.format(seg)).sort(['count'],ascending=[0])
res['segmentId'][i]=seg
recommendation='['
for index, x in d.iterrows():
item=str(x['ItemId'])
recommendation = recommendation + item + ','
recommendation = recommendation[:-1] + ']'
res['recommendation'][i]= recommendation
i=i+1
else:
res = pd.DataFrame(columns=[seg,pdver],index=[range(segmentCount)])
return res,
When in an experiment it returned the actual itemIds, when in webservice it returns some numbers, the purpose of this code is to pivot some table by segment column for the recommendation.