How do you reshape measurement columns into plotting rows?

pandas.melt keeps identifier columns and turns selected measurement columns into variable and value columns for grouped analysis.

melt in practice

Two students with math and physics columns produce four long-form rows. Since identifiers repeat after reshaping, count unique student IDs when counting people.

中文

怎样把多个测量列变成适合绘图的长表?

pandas.melt 保留标识列,把选中的测量列拆成变量名与数值两列,便于按变量分组。

melt 应用实例

两位学生各有数学和物理成绩,保留 student_id 并展开两个成绩列即可得到四行。展开会复制标识,后续按学生计数要用唯一标识。

References / 参考来源

Keep reading / 继续阅读