如何知道一列是否是另一列的倍数?

huangapple go评论120阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年6月5日 13:22:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76403656.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定