Sorting Data
Sorting helps you organize and analyze your data. Pandas provides flexible sorting methods.
Sorting by Single Column
Use sort_values() to sort by a column:
Loading Pandas Playground...
Sorting by Multiple Columns
Sort by multiple columns with different orders:
Loading Pandas Playground...
Sorting by Index
Sort by the row index:
Loading Pandas Playground...
Handling Missing Values
Control where NaN values appear:
Loading Pandas Playground...
In-Place Sorting
Modify the original DataFrame:
Loading Pandas Playground...
Sorting Columns
Sort columns instead of rows:
Loading Pandas Playground...
Exercise: Sort by Score
Loading Exercise...
Exercise: Multi-Column Sort
Loading Exercise...
Key Points
sort_values()sorts by column valuessort_index()sorts by indexascending=Falsefor descending order- Pass lists to sort by multiple columns
na_position='first'or'last'for NaN placementinplace=Truemodifies the original DataFrameaxis=1to sort columns
التالي · الدرس 13 من 42
Top N Values
قراءة 1 دقيقة
أنهيت 12 من 42 درسًا

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

