0

I have a dataframe that looks like this:

| 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 |

and I want it to look like:

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

I've seen a few questions were they want to do something similar but starting just from one column such as [Jess, Mary, Jones]. Any way I can do that?

DCN
  • 137
  • 1
  • 11
  • Check [this solution](https://stackoverflow.com/a/54783415/2901002) - `df1 = (df.set_index(["ID"]) .stack() .reset_index(level=1, drop=True) .reset_index(name='Name'))` – jezrael Oct 08 '19 at 05:32
  • Thanks, but that's not exactly the same question. I don't have all the names in one column as opposed to that question. – DCN Oct 08 '19 at 05:33
  • Not understand, solution from comment not working? – jezrael Oct 08 '19 at 05:35

0 Answers0