Skip to main content
Post Closed as "Not suitable for this site" by Reinderien, toolic, Toby Speight
Became Hot Network Question
added 9 characters in body; edited title
Source Link
tdy
  • 2.3k
  • 1
  • 10
  • 21

Finding Specific Promotionsspecific promotions from two columns

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
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 AD03ADO3 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"]

Finding Specific Promotions from two columns

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 AD03 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"]

Finding specific promotions from two columns

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"]
deleted 3 characters in body
Source Link
toolic
  • 16.4k
  • 6
  • 29
  • 221

0

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()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 AD03 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"]

0

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 AD03 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"]

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 AD03 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"]
Source Link
Gage
  • 41
  • 1

Finding Specific Promotions from two columns

0

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 AD03 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"]