2021年4月7日星期三

Group by and update value if occurs in any sub segment using python

I have a data frame with below columns, using which need to create new columns by grouping Name. Status should be updated as active to entire group if it is active for any one St.

data = {'Name':['Tom', 'Tom', 'krish', 'jack','jack','Nam','sue'],          'St':['S-123', 'S-290', 'S-123', 'S-147','S-98','S-123','S-38'],          'Status':['Inactive','active','active','inactive','active','Inactive','Inactive']}      df = pd.DataFrame(data)  

The desired output is

    Name     St    Status New Status  0    Tom  S-123  Inactive     active  1    Tom  S-290    active     active  2  krish  S-123    active     active  3   jack  S-147  inactive     active  4   jack   S-98    active     active  5    Nam  S-123  Inactive   Inactive  6    sue   S-38  Inactive   Inactive  
https://stackoverflow.com/questions/66996820/group-by-and-update-value-if-occurs-in-any-sub-segment-using-python April 08, 2021 at 11:07AM

没有评论:

发表评论