我有一个数据帧df表,有3列,比如:
[IN]:df
[OUT]:
Tree Name Planted by Govt Planted by College
A Yes No
B Yes No
C Yes No
C Yes No
A No No
B No Yes
B Yes Yes
B Yes No
B Yes No
查询:
每种树有多少棵是由政府种植的,而不是由大学种植的。政府:是,私人:否
需要输出:
1 Tree(s) 'A' were planted by govt and not by college
3 Tree(s) 'B' were planted by govt and not by college
2 Tree(s) 'C' were planted by govt and not by college
有人能帮忙吗
或者我们可以用count
首先通过比较按位
AND
用&
链接的两个列来创建布尔掩码,然后用聚合sum
转换为数字:最后一个自定义输出使用
f-string
s:另一个想法是根据原文创建新专栏:
相关问题 更多 >
编程相关推荐