Python Pandas - Mutiple assignment -


is there efficient way make following assignment without using loops?

for in range(0,len(df3)):     if df3.loc[i,'field'] == "a":         df3.loc[i,'field'] = "111"     elif df3.loc[i, 'field'] == "b":         df3.loc[i, 'field'] = "222"     elif df3.loc[i, 'field'] == "c":         df3.loc[i, 'field'] = "333"     else:         df3.loc[i,'field'] = "444" 

you can shorten code, still need loop hop through df3 structure , hit "field" fields.

xlate = {'a':'111', 'b':'222', 'c':'333'} in range(len(df3)):     df3.loc[i, 'field'] = xlate.get(df3.loc[i, 'field'], '444') 

Comments