In data analytics, data typically arrives in one of two formats:
pd.melt()pd.melt() unpivots a DataFrame from wide format to long format:
Output:
stack() & unstack()stack(): Pivots the innermost column level to the innermost row index level (makes DataFrame taller and narrower).unstack(): Pivots the innermost row index level to the innermost column level (makes DataFrame shorter and wider).pd.melt(df, id_vars=['City']), what do the columns in id_vars represent?df.unstack() do?pd.melt(), which parameters customize the names of the resulting melted columns?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Relational Joins with pd.merge (Inner, Left, Right, Outer) | DateTime Parsing, Indexing & .dt Accessor |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
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.