Rename Index of pandas DataFrame in Python (2 Examples) | Change Name | Convert Column to Indices

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

import pandas as pd # Import pandas library in Python

data = pd.DataFrame({'x1':[6, 7, 3, 7, 5, 9], # Create example DataFrame
'x2':['a', 'x', 'a', 's', 'a', 'b'],
'x3':range(7, 1, - 1)})
print(data) # Print example DataFrame
# x1 x2 x3
# 0 6 a 7
# 1 7 x 6
# 2 3 a 5
# 3 7 s 4
# 4 5 a 3
# 5 9 b 2

print(data) # Print updated DataFrame
# x1 x2 x3
# index_name
# 0 6 a 7
# 1 7 x 6
# 2 3 a 5
# 3 7 s 4
# 4 5 a 3
# 5 9 b 2

print(data) # Print updated DataFrame
# x1 x2
# x3
# 7 6 a
# 6 7 x
# 5 3 a
# 4 7 s
# 3 5 a
# 2 9 b

Follow me on Social Media:

Рекомендации по теме