I have a Pandas dataframe that represents an organigram with 11 levels that looks like this:
| level0 | level1 | level2 | level3 |
|---|---|---|---|
| Emma | John | Jason | |
| Emma | John | Hamza | Michael |
| Emma | John | Hamza | Olivia |
| Emma | Adam | Jaber | |
| Emma | Adam | Noah | |
| Emma | Catherine | Kate | Frank |
My desired output would look like this, where each new column cell is separated to a new row:
| level0 | level1 | level2 | level3 |
|---|---|---|---|
| Emma | |||
| John | |||
| Jason | |||
| Hamza | |||
| Michael | |||
| Olivia | |||
| Adam | |||
| Jaber | |||
| Noah | |||
| Catherine | |||
| Kate | |||
| Frank |
Using pandas.shift I've been able to get this dataframe:
| level0 | level1 | level2 | level3 |
|---|---|---|---|
| Emma | John | Jason | |
| Hamza | Michael | ||
| Olivia | |||
| Adam | Jaber | ||
| Noah | |||
| Catherine | Kate | Frank |
But I can't find a way to add the needed depth. Any suggestions?
Here's my code:
shifted_organigram= organigram.shift(1)
final_organigram=organigram[organigram.loc[:]!=shifted_organigram.loc[:]]
final_organigram = final_organigram.fillna("")```