Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # The script MUST contain a function named azureml_main
- # which is the entry point for this module.
- # imports up here can be used to
- import pandas as pd
- # The entry point function can contain up to two input arguments:
- # Param<dataframe1>: a pandas.DataFrame
- # Param<dataframe2>: a pandas.DataFrame
- def azureml_main(dataframe1 = None, dataframe2 = None):
- # Execution logic goes here
- print(f'Input pandas.DataFrame #1: {dataframe1}')
- # If a zip file is connected to the third input port,
- # it is unzipped under "./Script Bundle". This directory is added
- # to sys.path. Therefore, if your zip file contains a Python file
- # mymodule.py you can import it using:
- # import mymodule
- # Return value must be of a sequence of pandas.DataFrame
- # E.g.
- # - Single return value: return dataframe1,
- # - Two return values: return dataframe1, dataframe2
- products = {}
- for i in range(len(dataframe1['Продукт'])):
- name = dataframe1['Продукт'][i]
- if name in products:
- products[name] += dataframe1['Выручка'][i]
- else:
- products[name] = dataframe1['Выручка'][i]
- data = {}
- data['Продукт'] = list(products.keys())
- result = pd.DataFrame(data)
- result['Выручка'] = list(products.values())
- periods = {}
- for i in range(2018 * 12 + 7, 2019 * 12 + 6):
- periods[i] = {}
- for i in range(len(dataframe1['Продукт'])):
- date = dataframe1['Дата'][i]
- try:
- date_azure = int(date)
- base = datetime.datetime(1899,12,30)
- delta = datetime.timedelta(days=date_azure)
- date1 = base + delta
- except ValueError:
- date1 = dt.strptime(date, "%d.%m.%Y")
- m = date1.month
- y = date1.year
- name = dateframe1['Продукт'][i]
- income = dateframe1['Выручка'][i]
- month = y * 12 + m
- if name in periods[month]:
- periods[month][name] += income
- else:
- periods[month][name] = income
- xyz = []
- for name in products:
- mean = 0.0
- for month in periods:
- if name in periods[month]:
- mean += periods[month][name]
- mean /= len(periods)
- sigma = 0.0
- for month in periods:
- if name in periods[month]:
- sigma += (periods[month][name] - mean) ** 2
- else:
- sigma += mean ** 2
- sigma /= len(periods)
- sigma = sigma ** 0.5
- var = 1.0 * sigma / mean
- if 100 * var <= 85:
- xyz.append('X')
- continue
- if 100 * var <= 100:
- xyz.append('Y')
- continue
- else:
- xyz.append('Z')
- continue
- result['ABC'] = pd.Series(len(products), index=result.index)
- for i in range(len(products)):
- result['XYZ'][i] = xyz[i]
- result.sort_values(by=['Выручка'], ascending=False, inplace=True)
- sumOfIncomes = result['Выручка'].sum()
- result = result.reset_index(drop=True)
- accumulate = 0
- s = result['Выручка']
- for i in range(len(products)):
- accumulate += s[i]
- if (accumulate <= 0.7 * sumOfIncomes):
- result['ABC'][i] = 'A'
- elif (accumulate <= 0.9 * sumOfIncomes):
- result['ABC'][i] = 'B'
- else:
- result['ABC'][i] = 'C'
- result.drop('Выручка', axis=1, inplace=True)
- return [result]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement