Skip to content
Advertisement

Splitting Dataframe into different group by product

I am trying to split my Dataframe such that each Dataframe is for a product. Given below is how my Dataframe looks like:

JavaScript

Expected output:

Dataframe for prod_a

JavaScript

Dataframe for prod_b

JavaScript

Dataframe for prod_c

JavaScript

Advertisement

Answer

I suggest here create dictionary of DataFrames in dictionary comprehension:

JavaScript

Variables from strings are not recommended, but possible, e.g. with globals:

JavaScript

Another idea with groupby, thank you @Lunalo John for idea:

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