从熊猫中的宽形式组成的小组
我有这样的数据框架:
customer_type age satisfaction design food wifi service distance
Loyal 28 Not Satisfied 0 1 2 2 13.5
Loyal 55 Satisfied 5 3 5 4 34.2
Disloyal 36 Not Satisfied 2 0 2 4 55.8
Disloyal 28 Not Satisfied 3 1 2 2 13.5
Disloyal 33 Not Satisfied 2 1 2 2 13.5
Disloyal 35 Not Satisfied 2 1 2 2 13.5
Disloyal 39 Not Satisfied 1 1 2 2 13.5
Disloyal 31 Not Satisfied 2 1 2 2 13.5
Loyal 28 Not Satisfied 0 1 2 2 13.5
Disloyal 31 Not Satisfied 2 1 2 2 13.5
Disloyal 40 Not Satisfied 2 1 2 2 13.5
Disloyal 35 Not Satisfied 2 1 2 2 13.5
Disloyal 35 Not Satisfied 2 2 2 2 13.5
我想找出不忠
和不满足
的客户的特征他们的评分:
service ratings_count age age_count population_pct
design 8 40 1 7.69
36 1 7.69
35 3 23.07
33 1 7.69
31 2 15.38
food 1 35 1 7.69
我怀疑我必须使用代码> ,但我无法从那里弄清楚如何groupby
。
I have a DataFrame like this one:
customer_type age satisfaction design food wifi service distance
Loyal 28 Not Satisfied 0 1 2 2 13.5
Loyal 55 Satisfied 5 3 5 4 34.2
Disloyal 36 Not Satisfied 2 0 2 4 55.8
Disloyal 28 Not Satisfied 3 1 2 2 13.5
Disloyal 33 Not Satisfied 2 1 2 2 13.5
Disloyal 35 Not Satisfied 2 1 2 2 13.5
Disloyal 39 Not Satisfied 1 1 2 2 13.5
Disloyal 31 Not Satisfied 2 1 2 2 13.5
Loyal 28 Not Satisfied 0 1 2 2 13.5
Disloyal 31 Not Satisfied 2 1 2 2 13.5
Disloyal 40 Not Satisfied 2 1 2 2 13.5
Disloyal 35 Not Satisfied 2 1 2 2 13.5
Disloyal 35 Not Satisfied 2 2 2 2 13.5
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:
service ratings_count age age_count population_pct
design 8 40 1 7.69
36 1 7.69
35 3 23.07
33 1 7.69
31 2 15.38
food 1 35 1 7.69
I suspect I have to use melt
but I can't figure out how to groupby
from there.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用以下玩具数据框,受您的启发,但有点异质:
这是一个较少的子尾部,尽管更容易做到这一点:
因此:
从这里,您可以过滤
ratings_count&lt ; = 2
这样:With the following toy dataframe, inspired by yours but a bit more heterogeneous:
Here is one less subtel, although easier, way to do it:
So that:
From here, you can filter
ratings_count <=2
like this: