Pandas DataFrame: How to Reindex and Reset Index (3 Easy Examples) πŸ“Š

Learn how to reset and reindex your pandas DataFrame in Python with clear, step-by-step examples. Perfect for data cleaning and organization!

Pandas DataFrame: How to Reindex and Reset Index (3 Easy Examples) πŸ“Š
Statistics Globe
2.4K views β€’ Jun 6, 2022
Pandas DataFrame: How to Reindex and Reset Index (3 Easy Examples) πŸ“Š

About this video

How to reset and reindex the indices of a pandas DataFrame in the Python programming language. More details: https://statisticsglobe.com/reindex-pandas-dataframe-python
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]

data_new1 = data.reindex(new_index) # Apply reindex function
print(data_new1) # Print updated DataFrame

data_new2 = data.reset_index(drop = True) # Apply reset_index function
print(data_new2) # Print updated DataFrame

data_new3 = data.sort_index() # Apply sort_index function
print(data_new3) # Print updated DataFrame

Follow me on Social Media:
Facebook – Statistics Globe Page: https://www.facebook.com/statisticsglobecom/
Facebook – Group for Discussions & Questions: https://www.facebook.com/groups/statisticsglobe
LinkedIn – Statistics Globe Page: https://www.linkedin.com/company/statisticsglobe/
LinkedIn – Group for Discussions & Questions: https://www.linkedin.com/groups/12555223/
Twitter: https://twitter.com/JoachimSchork

Music by bensound.com

Tags and Topics

Browse our collection to discover more content in these categories.

Video Information

Views

2.4K

Likes

22

Duration

4:06

Published

Jun 6, 2022

User Reviews

4.2
(2)
Rate:

Related Trending Topics

LIVE TRENDS

Related trending topics. Click any trend to explore more videos.