Skip to content
Advertisement

How to combine rows into seperate dataframe python pandas

i have the following dataset:

JavaScript

i want to combine x y z into another dataframe like this:

JavaScript

and i want these dataframes for each x y z value like first, second third and so on.

how can i select and combine them?

desired output:

JavaScript

Advertisement

Answer

Use GroupBy.cumcount for counter and then loop by another groupby object:

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