User Tools

Site Tools


renaming_strings

Single Column Renaming

df.rename(columns={'a':'log(a)'}, inplace=True)

Multiple Columns Renaming

# method 1
df = df.rename(columns = {
    'col1 old name':'col1 new name',
    'col2 old name':'col2 new name',
    'col3 old name':'col3 new name',
})
 
# method 2
old_names = ['name1',
             'name2',
             'name3'] 
 
new_names = ['NAME1',
             'NAME2',
             'NAME3'] 
 
df.rename(columns=dict(zip(old_names, new_names)), inplace=True)

Renaming by replacing a character

applicata.rename(columns=lambda x: x.strip().replace(" ", ""), 
                 inplace=True)
renaming_strings.txt · Last modified: 2016/10/07 15:45 by vincenzo