MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Setting, Resetting & Managing Indices0%
Study MaterialsCheatsheet
PandasProgress 0%
1.1What is Pandas & Core Architecture1.2Pandas Installation & Environment Setup1.3Creating Series & DataFrames from Scratch
3.1Indexing with loc & iloc3.2Boolean Indexing & DataFrame Querying3.3Setting, Resetting & Managing Indices
HomeTutorialsPandasSetting, Resetting & Managing Indices
Detecting Missing Values (isna, notna, isnull)

Setting, Resetting & Managing Indices

Intermediate6 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

1. What is the DataFrame Index?

The Index is the backbone of relational alignment in Pandas. It provides unique labels that identify each row, enabling instant lookups, joins, and time-series resampling.

By default, when creating or loading a DataFrame, Pandas assigns a default zero-indexed integer range: RangeIndex(0, 1, 2, ...).


2. Setting an Existing Column as the Index (set_index)

When a column contains unique identifiers (like Employee_ID, Roll_No, or Timestamp), promoting it to the Index provides faster query speeds and cleaner semantics:

1import pandas as pd
2 
3df = pd.DataFrame({
4 'Emp_ID': ['E101', 'E102', 'E103', 'E104'],
5 'Name': ['Amit', 'Sunita', 'Karan', 'Pooja'],
6 'Department': ['Sales', 'IT', 'Finance', 'HR']
7})
8 
9# Promote 'Emp_ID' to be the Index
10df_indexed = df.set_index('Emp_ID')
11print(df_indexed)

Output:

1 Name Department
2Emp_ID
3E101 Amit Sales
4E102 Sunita IT
5E103 Karan Finance
6E104 Pooja HR

Now row lookups by employee ID are immediate:

1employee_record = df_indexed.loc['E102']

3. Resetting the Index (reset_index)

After filtering, sorting, or grouping, the index labels may become jumbled or discontinuous (e.g., rows 3, 7, 12). reset_index() restores a clean 0, 1, 2, ... index:

1# Revert 'Emp_ID' back to a normal column and restore integer range index
2df_restored = df_indexed.reset_index()
3print(df_restored)

Discarding the Old Index (drop=True)

If you filter rows and do not want the old index saved as a new column:

1df_filtered = df[df['Department'] == 'IT']
2# Reset index without keeping the old index column
3df_clean = df_filtered.reset_index(drop=True)

4. MultiIndex (Hierarchical Indexing)

Pandas allows DataFrames to have multiple index levels, enabling high-dimensional data representation in a 2D table:

1df_multi = df.set_index(['Department', 'Emp_ID'])
2print(df_multi)

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What does the df.set_index('Customer_ID') method do?
Question 2
What happens if you run df.reset_index(drop=True)?
Question 3
What is the default index type created when a DataFrame is initialized without specifying an index?
Question 4
Which parameter can be passed to df.set_index('col', inplace=True) to modify the original DataFrame directly?
Question 5
Can a DataFrame have multiple columns forming a composite, multi-level index?

Next Lesson

Detecting Missing Values (isna, notna, isnull)

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Boolean Indexing & DataFrame QueryingDetecting Missing Values (isna, notna, isnull)

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

12-Month Data Analysis Mastery Program

Master Full-Stack Data Analytics (Excel, SQL, Python, Power BI & Tableau)

Combine 15 complete courses, 150 chapters, 541 topics, live SQL/Power BI/Tableau dashboards, and Scikit-Learn capstones at MSK Institute Shikohabad or Live Online.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext