System: O365
IDE: JupyterLab
Language: Python version 3.7.3
Library: pandas version 1.0.1
Data source: personally built
Http API Documentation: https://github.com/RTICWDT/open-data-maker/blob/master/API.md
Hello, I am wondering if anyone knows how to return a value utilizing a conditional setting within a column range. For instance, I would like to return z-scores based on like values within a range changing once the next group of values is seen.
Steps were taken:
- built the below function it seems to be halfway there but not quite so
Code:
# get data
df0 = pd.read_csv('data/erpservicedesk.csv')
df0.columns
# put z-score into a lamda
zscore = lambda x: (x - x.mean()) / x.std()
# build datafram with the important features
df1 = df0[['Incident ID*+', 'Res.Prod.Cat.TierII', 'Res.Op.Cat.TierIII', 'Mean-Time-Tckt-Close']]
df1.insert(4,'ZofMTTC',df1.groupby(['Res.Prod.Cat.TierII', 'Res.Op.Cat.TierIII'])['Mean-Time-Tckt-Close'].transform(zscore))
df2 = df1.sort_values(by=['Res.Prod.Cat.TierII'])
df2.head(100)
Problem
It appears my lambda function is not conditional based on new column values as it seems to take the 'Mean-Time-Tckt-Close' for the entire dataframe rather than each new instance of 'Res.Prod.Cat.TierII'.
Example
A B C
Bob Store 10
Bob Store 11
Bob Store 8
Alfred Store 12
Alfred Store 9
I need a new column D to reflect the Z-Score for Bob and Alfred based off their respective data.