【问题标题】:How to get the cumulative count based on other column in googlesheets?如何根据谷歌表格中的另一列获取累积计数?
【发布时间】:2021-05-10 13:51:27
【问题描述】:

我试图从谷歌表格中的列创建一个具有每天累积计数的列,但我无法这样做。

如何获得累计数?

公开电子表格:https://docs.google.com/spreadsheets/d/10NzbtJhQj4hQBnZXcmwise3bLBIAWrE0qwSus_bz7a0/edit#gid=1126759670

问题

查找每天的累计数。例如,5 月 7 日从 1、2、3 开始,5 月 8 日又从 1、2、3 开始,依此类推。

必填

我需要如图所示的每一天的累计数。

【问题讨论】:

    标签: google-sheets


    【解决方案1】:

    在J2我进入

    =Arrayformula(IF(LEN(A2:A), ROW(C2:C)-MATCH(C2:C, C2:C,0),))
    

    看看这对你有用吗?

    【讨论】:

      【解决方案2】:

      还有

      =ArrayFormula(if(C2:C<>"",countifs(C2:C,C2:C,row(C2:C),"<="&row(C2:C)),))
      

      【讨论】:

        【解决方案3】:

        如果您有兴趣使用gspread 模块,可以按如下方式获取新列:

        import os
        import glob
        import numpy as np
        import pandas as pd
        
        import gspread
        
        path_creds = os.path.expanduser('~/.config/gspread/credentials.json')
        gc = gspread.service_account(filename=path_creds) # google service
        
        url = "https://docs.google.com/spreadsheets/d/10NzbtJhQj4hQBnZXcmwise3bLBIAWrE0qwSus_bz7a0/edit#gid=1126759670"
        
        parts = url.split('/edit')
        url = parts[0]
        sh = gc.open_by_url(url)
        ws = sh.sheet1
        res = ws.get_all_records()
        df = pd.DataFrame(res)
        df['answer'] = df.groupby('Date')['Company'].transform('cumcount')+1
        df
        

        输出

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-08-26
          • 2021-07-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-11-11
          • 2020-11-28
          • 1970-01-01
          相关资源
          最近更新 更多