python column rename code explanation needed -


1.my instructor did extremely poor job explaining code, explain me if 5 year old! familiar iterations , loops, having trouble renaming columns in python data frame. if conceptually explain each part excellent! here code:

    col in df.columns:         if col[:2] == '01':             df.rename(columns={col:'gold'+col[4:]}, inplace = true)         if col[:2] == '02':             df.rename(columns={col:'silver'+col[4:]}, inplace = true)         if col[:2] == '03':             df.rename(columns={col:'bronze'+col[4:]}, inplace = true)         if col[:1] == '#' :             df.rename(columns={col:'#'+col[4:]}, inplace = true)     df.head() 


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -