pandas description of dataframe renaming column values

Solutions on MaxInterview for pandas description of dataframe renaming column values by the best coders in the world

showing results for - "pandas description of dataframe renaming column values"
Isidora
22 Jun 2020
1	dict = {
2    'Android': 'Android',
3    'Chrome OS': 'Chrome OS',
4    'Linux': 'Linux',
5    'Mac OS': 'macOS',
6    'No OS': 'No OS',
7    'Windows': 'Windows',
8    'macOS': 'macOS'
9}
10
11df['col'] = df['col'].map(dict)
Nicole
03 Aug 2017
1
2def modified_col (col):
3    col = col.strip()#removes white space
4    col = col.replace('Operating System','os')
5    col = col.replace(' ','_')
6    col = col.replace(')','')#removes (
7    col = col.replace('(','')
8    col = col.lower()
9    return col
10
11new_columns = []
12for new_col in df.columns:
13    clean_col = modified_col(new_col)
14    new_columns.append(clean_col)
15
16df.columns = new_columns