将pandas数据框从列扩展为行

时间:2019-10-08 05:28:15

标签: python pandas

我有一个看起来像这样的数据框:

| ID    | Name1 | Name2 | Name3 | Name4|
|id001  | Jesse | Mary  | Jones | None |
|id002  | Phil  | None  | None  | None |
|id003  | Liam  | Ben   | Rose  | Kate |
|id004  | Chris | David | Diana | None |

并且我希望它看起来像:

| ID    | Name  |
|id001  | Jesse |
|id001  | Mary  |
|id001  | Jones |
|id002  | Phil  |
|id003  | Liam  |
|id003  | Ben   |
|id003  | Rose  |
|id003  | Kate  |
|id004  | Chris |
|id004  | David |
|id004  | Diana |   

我已经看到了几个问题,他们是否想做类似的事情,但仅从[Jess,Mary,Jones]之类的专栏开始。我能做到吗?

0 个答案:

没有答案