Python Write Value From Dictionary Based On Match In Range Of Columns
From my df showing employees with multiple levels of managers (see prior question here), I want to map rows to a department ID, based on a manager ID that may appear across multipl
Solution 1:
I added a solution, if manager columns (mid,l2mid,l3mid) value match the dictionary keys, then the values are joined splitted by ,
:
s = df.drop('eid',1).applymap(country.get)
.dropna(how='all', axis=0)
.apply(lambda x: ', '.join(x.dropna()), 1)
df = df.loc[s.index].assign(country=s)
print (df)
eid mid l2mid l3mid country
0 111 112 114 115 US, Ireland
1 113 114 115 0 Ireland
2 112 114 118 0 Ireland
4 116 118 0 0 Mexico
Post a Comment for "Python Write Value From Dictionary Based On Match In Range Of Columns"