英文:
How to know if a column is multiple of other?
问题
如何知道一列是否是另一列的倍数?
有多少列销售额的注册是通话次数的倍数?
| 销售额 | 通话次数 |
| 8 | 10 |
| 5 | 3 |
| 6 | 3 |
...
一直在思考一个真假解决方案,然后计算有多少个真和假。
一直在考虑一个布尔解决方案。
英文:
How to know if a column is multiple of other?
How many registers of column sales are multiple of calls?
|Sales|Calls|
| 8 | 10 |
| 5 | 3 |
| 6 | 3 |
...
Been thinking a true or false solution and then counting how many true and false are
Been thinking about a boolean solution
答案1
得分: 2
以下是翻译好的内容:
import pandas as pd
df = pd.DataFrame({
'销售': [8, 5, 6],
'电话呼叫次数': [10, 3, 3]
})
df["倍数"] = df['销售'] % df['电话呼叫次数'] == 0
print(df.倍数.sum())
输出:
1
这仅适用于数据是整数的情况。如果在您的计数中有零,您需要在此之前对其进行过滤。
英文:
Expanding on @neilfws comment try this in Python:
import pandas as pd
df = pd.DataFrame({
'Sales': [8, 5, 6],
'Calls': [10, 3, 3]
})
df["multiples"] = df['Sales'] % df['Calls'] == 0
print(df.multiples.sum())
Printout:
1
This only works if your data are integers. If you have zeroes in your counts you need to filter these beforehand.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论