Reindex & Reset Index of pandas DataFrame from 0 in Python (3 Examples) | reset_index & sort_index

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

import pandas as pd # Import pandas

data = pd.DataFrame({'x1':range(10, 18), # Create pandas DataFrame
'x2':['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'],
'x3':range(8, 0, - 1)},
index = [5, 6, 2, 1, 4, 7, 0, 3])
print(data) # Print pandas DataFrame

new_index = [1, 6, 2, 7, 0, 3, 5, 4] # Create list for new index
print(new_index) # Print new index
# [1, 6, 2, 7, 0, 3, 5, 4]

print(data_new1) # Print updated DataFrame

print(data_new2) # Print updated DataFrame

print(data_new3) # Print updated DataFrame

Follow me on Social Media:

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

Hello Joachim. Thanks to God I found this video. With all my sincerity, thank you so much for this video. I was stuck with a reset index. You showed me dfhistorical_rates_tab = dfmspentab.copy()
Thank you so much. God bless you.

miguelfernandovalenzueladi