Set Index in Pandas DataFrame (Python) πŸ“Š

Learn how to set a DataFrame column as index using pandas' set_index() with an example in Python.

Set Index in Pandas DataFrame (Python) πŸ“Š
Statistics Globe
285 views β€’ Jun 10, 2022
Set Index in Pandas DataFrame (Python) πŸ“Š

About this video

How to add a column of a pandas DataFrame as an index in the Python programming language. More details: https://statisticsglobe.com/set-index-pandas-dataframe-python
Python code of this video:

import pandas as pd # Load pandas library

data = pd.DataFrame({'x1':range(10, 15), # Create pandas DataFrame
'x2':['a', 'b', 'c', 'd', 'e'],
'x3':range(10, 5, - 1)})
print(data) # Print pandas DataFrame

data_new = data.set_index('x2') # Apply set_index function
print(data_new) # 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

285

Likes

8

Duration

2:32

Published

Jun 10, 2022

Related Trending Topics

LIVE TRENDS

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