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
Post a Comment