【问题标题】:Excel using SUMPRODUCT to find number of times a value appears in a column and in pythonExcel 使用 SUMPRODUCT 查找值在列和 python 中出现的次数
【发布时间】:2022-01-06 20:22:08
【问题描述】:

所以我有这个 Excel 表,其中有一列并用 1 和 0 填充

4 表示列中 1 的最大数量,我不知道如何获得该数字。 我想知道是否有办法让它在 excel 中返​​回类似的内容:

这样在数字停止重复后会有一个新列,它会告诉你它重复了多少次。

我用 python 做这个的想法是这样的,但我还没有。

listas = [1,1,0,1,0,1,1,1,1,0]
new_column = []
count = 1
for i in range(len(listas)):
   print(listas[i])
   if listas[i] == 1:
    
    new_column.append(count)
    if listas[i+1] == 1:
        count = count + 1
        new_column.append(count)
    # so if the first integer is 1 check the one in the next position and if 1 coninute checking until 0

所以new_column 是[2,0,1,0,4,0] 返回 0 或 na 所以它只是空的

我将如何在 excel 或 python 中完成此操作?

【问题讨论】:

    标签: python excel list


    【解决方案1】:

    Excel 中的标准方法是使用FREQUENCY 函数:

    =MAX(FREQUENCY(IF(MyRange,ROW(MyRange)),IF(1-MyRange,ROW(MyRange))))

    这可能需要也可能不需要使用 CTRL+SHIFT+ENTER 提交,具体取决于您的 Excel 版本。

    【讨论】:

      【解决方案2】:

      将此公式放入B2并填写: =LET(x,IF(A2=0,SUM(A$1:A1)-SUM(B$1:B1),0),IF(x=0,"",x))

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-12-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-06-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多