计算具有高于阈值的值的列数
假设我有以下玩具模型,df
:
product customer1 customer2 customer3
apple 40 110 120
banana 200 150 180
coconut 10 5 25
daq 120 10 30
eclair 45 190 35
我想将一列添加到df
中,该计算了购买至少一百个列出的项目的客户数:
product customer1 customer2 customer3 atleast100
apple 40 110 120 2
banana 200 150 180 3
coconut 10 5 25 0
daq 120 10 30 1
eclair 45 190 35 1
Assuming I have the following toy model, df
:
product customer1 customer2 customer3
apple 40 110 120
banana 200 150 180
coconut 10 5 25
daq 120 10 30
eclair 45 190 35
I would like to add a column to df
that counts the number of customers that bought at least a hundred of the items listed:
product customer1 customer2 customer3 atleast100
apple 40 110 120 2
banana 200 150 180 3
coconut 10 5 25 0
daq 120 10 30 1
eclair 45 190 35 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在
客户
列中,使用ge()。sum()
来计算每行大或等于100的值。Among the
customer
columns, count the number of values greater or equal to 100 in each row usingge().sum()
.尝试以下操作:
Try this: