Skip to content
Advertisement

Data-frame columns into list of lists using Groupby

A data-frame and I want to transform it.

JavaScript

enter image description here

The ideal result is something like:

JavaScript

I tried:

JavaScript

also:

JavaScript

But not getting nearer.

What’s the right way?

Advertisement

Answer

You can do:

JavaScript

Output:

JavaScript

If you want the list in the correct order, you would need to re-order your columns. For example:

JavaScript

And you get:

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