Created
October 26, 2019 17:09
-
-
Save adrepd/c366df3ce8607ff910db5e920f288790 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def consolidado(data): | |
def getCosecha(mini, maxi, leni): | |
cosechasIni = {201809: 1, 201810: 2, 201811: 3, 201812: 4} | |
cosechasFin = {201902: 1, 201903: 2, 201904: 3, 201905: 4} | |
if mini in cosechasIni and maxi in cosechasFin and (cosechasIni[mini] == cosechasFin[maxi]) and leni== 6: | |
return cosechasIni[mini] | |
else: | |
return 0 | |
xmax = data.groupby(by = ['ID2']).max().loc[:,'PERIODO'].to_dict() | |
xmin = data.groupby(by = ['ID2']).min().loc[:,'PERIODO'].to_dict() | |
xcount = data.groupby(by = ['ID2']).count().loc[:,'PERIODO'].to_dict() | |
# personalizar esto | |
xMONTO_DEUDA = data.groupby(by = ['ID2']).mean().loc[:,'MONTO_DEUDA'].to_dict() | |
xTARDANZA_PAGO = data.groupby(by = ['ID2']).mean().loc[:,'TARDANZA_PAGO'].to_dict() | |
datosCosecha = [] | |
for id1 in xmin.keys(): | |
cosecha = getCosecha(xmin[id1], xmax[id1], xcount[id1]) | |
#personalizar esto | |
datosCosecha.append([id1, cosecha, xMONTO_DEUDA[id1], xTARDANZA_PAGO[id1]]) | |
# personalizar estas cabeceras | |
return pd.DataFrame(datosCosecha, columns = ['ID2' , 'COSECHA', 'DEUDA_PROM', 'TARDANZA_PROM']) | |
cons = consolidado(tabla_facturacion_no_nula) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment