testRolling.py 627 B

1234567891011121314151617181920212223242526272829
  1. # import pandas as pd
  2. # print(df)
  3. df = None
  4. #连续计算算法
  5. def calcContinuos(x):
  6. max=0
  7. tmp=0
  8. for a in x:
  9. if a>=1 :
  10. tmp=tmp+1
  11. else:
  12. if tmp>max:
  13. max=tmp
  14. tmp=0
  15. if max<tmp:
  16. max=tmp
  17. return max
  18. #获取最大连续逾期月份数
  19. def getContinuousOverdueMonth(df,month):
  20. result = df.rolling(month).apply(calcContinuos).max()
  21. return int(result);
  22. if __name__ == '__main__':
  23. import modin.pandas as pd
  24. df = pd.DataFrame([2, 3, 4, 5, 6, 7])
  25. print(getContinuousOverdueMonth(df,6))