Note
Pandas (39) 본문
728x90
How to rename a specific columns in a dataframe?
# Input
df = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/Cars93_miss.csv')
# Solution
# Step 1:
df=df.rename(columns = {'Type':'CarType'})
# or
df.columns.values[2] = "CarType"
# Step 2:
df.columns = df.columns.map(lambda x: x.replace('.', '_'))
print(df.columns)
# output
Index(['Manufacturer', 'Model', 'CarType', 'Min_Price', 'Price', 'Max_Price',
'MPG_city', 'MPG_highway', 'AirBags', 'DriveTrain', 'Cylinders',
'EngineSize', 'Horsepower', 'RPM', 'Rev_per_mile', 'Man_trans_avail',
'Fuel_tank_capacity', 'Passengers', 'Length', 'Wheelbase', 'Width',
'Turn_circle', 'Rear_seat_room', 'Luggage_room', 'Weight', 'Origin',
'Make'],
dtype='object')
'Pandas' 카테고리의 다른 글
Pandas (41) (0) | 2022.09.04 |
---|---|
Pandas (40) (0) | 2022.09.03 |
Pandas (38) (0) | 2022.08.30 |
Pandas (37) (0) | 2022.08.29 |
Pandas (36) (0) | 2022.08.28 |
Comments