Я пытаюсь построить график CDF для своего кода с помощью Seaborn, но не могу заставить его работать.
В частности, я хочу создать графики CDF для sum_MDA, sum_CLA, sum_BIA и grand_total после я смоделировал весь код 1000 раз.Мой код выглядит следующим образом (заранее извиняюсь за длину).
def sim():
df['RAND'] = np.random.uniform(0,1, size=df.index.size)
dfRAND = list(df['RAND'])
def L():
result = []
conditions = [df.RAND >= (1 - 0.8062), (df.RAND < (1 - 0.8062)) & (df.RAND >= 0.1),
(df.RAND < 0.1) & (df.RAND >= 0.05), (df.RAND < 0.05) &
(df.RAND >= 0.025), (df.RAND < 0.025) & (df.RAND >= 0.0125),
(df.RAND < 0.0125)]
choices = ['L0', 'L1', 'L2', 'L3', 'L4', 'L5']
df['L'] = np.select(conditions, choices)
result = df['L'].values
return result
L()
#print(L())
#print(df.pivot_table(index='L', aggfunc=len, fill_value=0))
def MD():
result = []
conditions = [L() == 'L0', L() == 'L1', L() == 'L2', L() == 'L3',
L() == 'L4', L() == 'L5']
choices = [(df['P_MD'].apply(lambda x: x * 0.02)), (df['P_MD'].apply(lambda x: x * 0.15)),
(df['P_MD'].apply(lambda x: x * 0.20)), (df['P_MD'].apply(lambda x: x * 0.50)),
(df['P_MD'].apply(lambda x: x * 1.0)), (df['P_MD'].apply(lambda x: x * 1.0))]
df['MDL'] = np.select(conditions, choices)
#result = print(df['MDL'].values)
return result
MD()
def CL():
result = []
conditions = [L() == 'L0', L() == 'L1', L() == 'L2', L() == 'L3', L() == 'L4',
L() == 'L5']
choices = [1600, 3200, 9600, 48000, 48000, 48000]
df['CL'] = np.select(conditions, choices)
#result = print(df['CL'].values)
return result
CL()
def BI():
result = []
conditions = [L() == 'L0', L() == 'L1', L() == 'L2', L() == 'L3',
L() == 'L4', L() == 'L5']
choices = [(df['P_BI'].apply(lambda x: (x / 548) * 1)),
(df['P_BI'].apply(lambda x: (x / 548) * 2)),
(df['P_BI'].apply(lambda x: (x / 548) * 14)),
(df['P_BI'].apply(lambda x: (x / 548) * 60)),
(df['P_BI'].apply(lambda x: (x / 548) * 180)),
(df['P_BI'].apply(lambda x: (x / 548) * 365))]
df['BIL'] = np.select(conditions, choices)
#result = print(df['BIL'].values)
return result
BI()
sum_MDA = int(np.sum(df['MDL']))
sum_CLA = int(np.sum(df['CL']))
sum_BIA = int(np.sum(df['BIL']))
grand_total = int(sum_MDA + sum_CLA + sum_BIA)
result = sum_MDA, sum_CLA, sum_BIA, grand_total
return result
sim()
for i in range(1000):
print(sim())
#sns.distplot(sim(), bins=100,
#kde_kws=dict(cumulative=True), axlabel='(£)', color='purple',
#).set_title('Simulation (N=1000)')
Любая помощь приветствуется.Большое спасибо.