I'm trying to build a function that identifies those who are promoted into a list of jobcodes, or are promoted within that list of jobcodes.
Initially I was using np.where()
until I realized it would actually capture those who were demoted as well.
Here's what I'm currently working with which works but I'm slightly unhappy with how it looks / appears. Does anyone have a different technique / approach for solving a problem like this?
Mostly curious if anyone has any criticism, thanks!
The idea is that anyone whose current paygroup is in "promotions" should be flagged if they've:
A) moved into there from a paygroup that isn't in the tuple
OR
B) assume AGM4 < GM2 < ADO3 and anyone who moves up that hierarchy should be considered promoted
def index_checker(cur,prev):
promotions = ("AGM4", "GM2","ADO3")
if cur not in promotions:
return False
else:
return promotions.index(cur) > promotions.index(prev) if prev in promotions and cur in promotions else True
df["Promoted"] = np.vectorize(index)(df["PayGroup_cur"].values,df["PayGroup_prev"].values)
df[df["Promoted"]==True].to_csv(r"location.csv")
This approach didn't work because it would consider someone who moved from ADO3 to AGM4 a promotion. I tried to add the logic of the index checker within this condition list, and then I kept running into broadcast shaping issues and truth ambiguities
promotions = ("AGM4", "GM2","ADO3")
condition = (np.isin(df["PayGroup_cur"].values,promotions) & (df["PayGroup_cur"].values != df["PayGroup_prev"].values) & (promotions.index(df["PayGroup_cur"].values) > promotions.index(df["PayGroup_cur"].values)))
df["Promoted"] = np.where(condition, "Promoted", "Not Promoted")
df[df["Promoted"]=="Promoted"]