Setting & Resetting Index
The index is the row label in a DataFrame. You can customize it for better data organization and lookup.
Default Index
By default, Pandas uses integer index starting from 0:
Loading Pandas Playground...
Setting a Column as Index
Use set_index() to make a column the index:
Loading Pandas Playground...
Resetting the Index
Use reset_index() to move the index back to a column:
Loading Pandas Playground...
Multi-Level Index
Create hierarchical indexes:
Loading Pandas Playground...
Modifying Index in Place
Use inplace=True to modify the original DataFrame:
Loading Pandas Playground...
Renaming the Index
Give your index a name:
Loading Pandas Playground...
Exercise: Set Index
Loading Exercise...
Exercise: Reset Index
Loading Exercise...
Key Points
set_index('column')makes a column the indexreset_index()moves index back to a columnreset_index(drop=True)discards the indexinplace=Truemodifies the original DataFrame- Multi-level indexes use tuples for lookup
- Index enables fast
.loc[]lookups
التالي · الدرس 10 من 42
Filtering Data
قراءة 1 دقيقة
أنهيت 9 من 42 درسًا

اسأل Byte عن هذا الدرس
محادثة خاصة حول هذا الدرس. قرأ Byte الدرس كاملًا، ويجيب خلال ثوانٍ، ويُظهر القسم الذي تأتي منه كل إجابة. يمكنك السؤال بأي لغة.
الأسئلة والأجوبة
أسئلة عامة حول هذا الدرس. يجيب AI Tutor فورًا بلغتك، ويراجع فريق FreeAcademy الإجابات، ويمكن لكل المتعلمين قراءتها.

