Skip to content
Advertisement

How to pivot a table based on the values of one column

let’s say I have the below dataframe:

JavaScript

which looks like this:

JavaScript

As you can see I have my wanted columns as rows in col1 and not all values have a Phone number, is there a way for me to transform this dataframe to look like this:

JavaScript

I have tried to transpose in Excel, do a Pivot and a Pivot_Table:

JavaScript

But this comes out incorrectly. any help would be appreciated on this.

NOTES: All new section start with the Name value and end before the Name value of the next person.

Advertisement

Answer

Create a new index using cumsum to identify unique sections then do pivot as usual…

JavaScript

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement