Skip to content
Advertisement

Group by from wide form in Pandas

I have a DataFrame like this one:

JavaScript

I want to find out the characteristics of the Disloyal and Not Satisfied customers that are between 30 and 40 years old, grouping them by the service they have rated:

JavaScript

I suspect I have to use melt but I can’t figure out how to groupby from there.

Advertisement

Answer

With the following toy dataframe, inspired by yours but a bit more heterogeneous:

JavaScript

Here is one less subtel, although easier, way to do it:

JavaScript

So that:

JavaScript

From here, you can filter ratings_count <=2 like this:

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