Rename Column of pandas DataFrame by Index in Python (Example) | Change Name | rename() Function

preview_player
Показать описание
Python code of this video:

import pandas as pd # Load pandas library

data = pd.DataFrame({'x1':range(50, 55), # Create pandas DataFrame
'x2':['a', 'd', 'x', 'a', 'd'],
'x3':range(7, 2, - 1),
'x4':['x', 'y', 'y', 'z', 'y']})
print(data) # Print pandas DataFrame

print(data_new) # Print updated DataFrame

Follow me on Social Media:

Рекомендации по теме
Комментарии
Автор

Thank you, thank you, thank you! I have a CSV where the first 2 columns have no values in the top row (I cannot control the CSVs so wanted to handle this programmatically) and have been wracking my brain trying to figure out how to address those columns to rename them.

FreihEitner