Created
July 6, 2017 05:19
-
-
Save saraswatmks/f2815cf1448a0baa00aeb1e255ccedc3 to your computer and use it in GitHub Desktop.
This solution calculates the value of process grouped by count of unique step nos * 0.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
# load libary - you might need to install xlrd library in case it throws any error in reading file | |
import pandas as pd | |
# read file | |
sensor = pd.read_excel("SENSOR-009.xlsx",sheetname="Sheet1") | |
def calculate(df): | |
second = pd.DataFrame() | |
# transform the data into table and convert the STEP NO in a list for further calculations | |
second = df.groupby('PROCESS NO')['STEP NO'].apply(lambda x: list(x)).reset_index() | |
# count the number of zeros | |
second['initialisation_time'] = [x.count(0) for x in second['STEP NO']] | |
# calculate the length of list | |
second['total_len'] = [len(x) for x in second['STEP NO']] | |
# subtract the length from zero to get count of steps other than 0 | |
second['after_initialisation_time'] = second['total_len'] - second['initialisation_time'] | |
# multipying the counts with 0.1 | |
second['initialisation_time'] = second['initialisation_time']*0.1 | |
second['after_initialisation_time'] = second['after_initialisation_time']*0.1 | |
second.drop(['total_len','STEP NO'],axis=1, inplace=True) | |
# the desired output | |
return second | |
# get solution file | |
solution = calculate(sensor) | |
#check solution | |
print (solution) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment