首页 > 解决方案 > Count historical rows

问题描述

I have a dataframe which contains operations, and I want to add a column which give for each user the number of history of operations (number of rows with lower date)

   user id      date      
        1   2020-10-01               
        2   2020-11-02               
        3   2020-08-03               
        1   2020-09-25              
        3   2020-09-11               
        1   2020-09-26        
        3   2020-10-26        
        1   2020-10-05        
        2   2020-11-03  

Output :

  user id       date     Number of last operation  
        1   2020-10-01        2         
        2   2020-11-02        0         
        3   2020-08-03        0         
        1   2020-09-25        0         
        3   2020-09-11        1         
        1   2020-09-26        1  
        3   2020-10-26        2 
        1   2020-10-05        3 
        2   2020-11-03        1

标签: pythondataframe

解决方案


推荐阅读