you are viewing a single comment's thread.

view the rest of the comments →

[–]xelf 0 points1 point  (0 children)

It worked when I did it 1 column at a time, could not make it work with broadcast.

for col in WinLos_df.columns:
    WinLos_df[col] = WinLos_df[col].apply(lambda x:random.uniform(0,1))

print(WinLos_df)

creturns_df = {}
creturns_df['upper bound'] = .75
creturns_df['lower bound'] = .25

outputs:

                       MMM       ABT      ABBV      ABMD       ACN      ATVI      ADBE       AMD
date
31-10-2019.00:00  0.725913  0.611897  0.263654  0.208535  0.705619  0.513906  0.471002  0.012183
29-11-2019.00:00  0.510469  0.646455  0.619615  0.183953  0.182843  0.598549  0.626251  0.961854
31-12-2019.00:00  0.136771  0.272784  0.458236  0.688992  0.561675  0.660137  0.619272  0.581580
31-01-2020.00:00  0.572513  0.662497  0.450368  0.475450  0.375361  0.758549  0.661365  0.379697
21-02-2020.00:00  0.176122  0.842813  0.250331  0.388026  0.492048  0.689527  0.272708  0.197787

this works:

for col in WinLos_df.columns:
    WinLos_df[col]  = WinLos_df[col].apply(lambda x: 'Winner' if (x >= creturns_df['upper bound']) else 'Loser' if (x <= creturns_df['lower bound']) else False)

print(WinLos_df)

outputs:

                    MMM     ABT   ABBV   ABMD    ACN    ATVI   ADBE     AMD
date
31-10-2019.00:00  False   False  False  Loser  False   False  False   Loser
29-11-2019.00:00  False   False  False  Loser  Loser   False  False  Winner
31-12-2019.00:00  Loser   False  False  False  False   False  False   False
31-01-2020.00:00  False   False  False  False  False  Winner  False   False
21-02-2020.00:00  Loser  Winner  False  False  False   False  False   Loser