Skip to content
Advertisement

Split data frame into multiple data frames based on a group of parameters in a column

I’ve got a data frame like this:

DF

JavaScript

And I need to split it in multiple data frames by PARAMETER_4 in C column, to get:

DF_1

JavaScript

DF_2

JavaScript

DF_3

JavaScript

I cannot find any easy-way function like df.split(axis=0, value='PARAMETER_4')

Any idea about an approach? Thank you in advance!

Advertisement

Answer

We can use groupby twice here. First we groupby on column C and make a cumcount. Then we groupby on this cumcount to get the seperate dataframes:

JavaScript

Output

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