Reshaping Data
Transform data between wide and long formats using melt(), stack(), and unstack().
Wide to Long with melt()
Convert columns into rows:
Loading Pandas Playground...
Long to Wide with pivot()
Convert rows into columns:
Loading Pandas Playground...
Stack and Unstack
Work with multi-level indices:
Loading Pandas Playground...
Melt Multiple Value Columns
Unpivot several columns at once:
Loading Pandas Playground...
Combining Melt with GroupBy
Reshape then aggregate:
Loading Pandas Playground...
Transpose
Swap rows and columns:
Loading Pandas Playground...
Exercise: Wide to Long
Loading Exercise...
Exercise: Long to Wide
Loading Exercise...
Key Points
melt()converts wide to long (unpivot)pivot()converts long to widestack()pivots columns to rowsunstack()pivots rows to columns.Ttransposes rows and columns- Long format is often better for analysis
- Wide format is often better for display
التالي · الدرس 34 من 42
Working with a DatetimeIndex
قراءة 2 دقيقة
أنهيت 33 من 42 درسًا

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

