I'm going a little further this previous question about mapping dictionary values to dataframes. I have a simple dataframe df like:
U,id
111,01
112,02
112,03
113,04
113,05
113,06
114,07
and I want to map on a new column the following nested dictionary:
d = {112: {'en': 1, 'es': 2}, 113: {'zh': 1, 'ja': 1, 'es': 2}, 114: {'es': 1}, 111: {'ar': 2, 'en': 1}}
taking into account only the most frequent L
values, i.e. 112:'es', 113:'es', 114:'es', 111:'ar'.
On a simple dictionary case, I can use df['C'] = df['U'].map(d)
. How can I do the same taking only the previous highest values? The resulting dataframe would appear as:
U,id,C
111,01,ar
112,02,es
112,03,es
113,04,es
113,05,es
113,06,es
114,07,es