1234567891011121314151617181920212223242526272829 |
- # import pandas as pd
- # print(df)
- df = None
- #连续计算算法
- def calcContinuos(x):
- max=0
- tmp=0
- for a in x:
- if a>=1 :
- tmp=tmp+1
- else:
- if tmp>max:
- max=tmp
- tmp=0
- if max<tmp:
- max=tmp
- return max
- #获取最大连续逾期月份数
- def getContinuousOverdueMonth(df,month):
- result = df.rolling(month).apply(calcContinuos).max()
- return int(result);
- if __name__ == '__main__':
- import modin.pandas as pd
- df = pd.DataFrame([2, 3, 4, 5, 6, 7])
- print(getContinuousOverdueMonth(df,6))
|