python画累计概率密度图

for i in sorted(list(set(df['yearmonth']))):
    df_sort = df[df['yearmonth'] == i].groupby('cust_id')['y','pred'].sum().sort_values('y',ascending = False)        
    df_sort['yearmonth'] = i
    df_sort['y_cum'] = np.cumsum(df_sort['y'])
    df_sort['y_cum_rate'] = df_sort['y_cum']/max(df_1_clear_sort['y_cum'])
    df_sort['index'] = list(range(1,df_sort.shape[0]+1))
    df_sort['index_cum_rate'] = [i/df_sort.shape[0] for i in list(range(1,df_sort.shape[0]+1))]
    print(df_sort[['yearmonth','index','y_cum_rate','pred']].head(5))
    
    plt.figure(figsize=(4,4))
    plt.plot(list(df_sort['index_cum_rate']),list(df_sort['y_cum_rate']))
    plt.title(i,fontsize=24)
    plt.xlabel('index_cum_rate',fontsize=14)
    plt.ylabel('y_cum_rate',fontsize=14)
    plt.grid(True)
    plt.show()

你可能感兴趣的:(python,python)