How to rename a specific range of columns in Python (Pandas) -
koak.rename(columns = lambda x : 'koak-' + x, inplace=true)
the above code allows me add 'koak' in front of column headers in data frame want add koak prefix column numbers 4-38. how go doing this?
you can assign columns
:
koak.columns = ['koak-' + x if 4 <= <= 38 else x i, x in enumerate(koak.columns, 1)]
example:
koak = pd.dataframe(dict.fromkeys('abcdefg', [12])) koak.columns = ['koak-' + x if 2 <= <= 4 else x i, x in enumerate(koak.columns, 1)] print(koak)
prints:
koak-b koak-c koak-d e f g 0 12 12 12 12 12 12 12
Comments
Post a Comment