def tenor(ltt):
if ltt <= 24*30: return 24
elif ltt <= 36*30: return 36
else: return 60
def buckclass(odues):
# Определение класса
if odues == 0: return 0
elif 0 < odues <= 30: return 1
elif 30 < odues <= 60: return 2
elif 60 < odues <= 90: return 3
elif 90 < odues <= 120: return 4
else: return 5
datareport = pd.DataFrame({'ODATE': {0:0},
'TENOR': {0:0},
'VDATE': {0:0},
'R': {0:0},
'RC': {0:0},
'DE': {0:0},
'I': {0:0},
'DEB': {0:0},
'D': {0:0}})
for nc in data.nc.unique():
# Просматриваем каждый ID
fordata = data[data.nc == nc].sort_values(by='vdate')
onrow = fordata.iloc[0,:]
for row in fordata.itertuples(index=False):
if (onrow.odate == row.odate) & (onrow.vdate == row.vdate) & (onrow.ball == row.ball):
ball_old = onrow.ball
bucket_class_old = 0
difference = ball_old - row.ball
datareport = pd.concat([datareport, pd.DataFrame({'ODATE': {0:row.odate},
'TENOR': {0:tenor(row.ltt)},
'VDATE': {0:row.vdate},
'R': {0:bucket_class_old},
'RC': {0:buckclass(row.odues)},
'DE': {0:row.ball},
'I': {0:0},
'DEB': {0:ball_old},
'D': {0:0}})])
datareport = pd.concat([datareport, pd.DataFrame({'ODATE': {0:row.odate},
'TENOR': {0:tenor(row.ltt)},
'VDATE': {0:row.vdate},
'R': {0:bucket_class_old},
'RC': {0:100},
'DE': {0:difference},
'I': {0:0},
'DEB': {0:ball_old},
'D': {0:0}})])
ball_old = row.ball
bucket_class_old = buckclass(row.odues)