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

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

node.js - Express and Redis - If session exists for this user, don't allow access -