I want to apply background colors to a data frame using 4 different masking data frames. Each mask_df is the same shape as df. The colors will depend on which masks are true/false.
rndm = pd.DataFrame(np.random.uniform(-15,15,size=(100, 4)), columns=list('ABCD'))
rndm_mask1 = pd.DataFrame(np.random.choice([0,1],size=(100, 4), p=[2./3, 1./3]), columns=list('ABCD'))
rndm_mask2 = pd.DataFrame(np.random.choice([0,1],size=(100, 4), p=[1./3, 2./3]), columns=list('ABCD'))
rndm_mask3 = pd.DataFrame(np.random.choice([0,1],size=(100, 4), p=[2./3, 1./3]), columns=list('ABCD'))
Logic
Basically:
- if rndm_mask1 is true (and rndm_mask2 and 3 are FALSE), background is red
- if rndm_mask2 is true, yellow
- if rndm_mask3 is true, blue
- if rndm_mask1 AND rndm_mask2 are true, orange
- if rndm_mask2 AND rndm_mask3 are true, green
- if rndm_mask1 AND rndm_mask3 are true, purple
Problem:
I'm not sure how to chain all these styling logics into one cohesive function. The pd.DataFrame.style.apply() method requires list like outputs which I'm having trouble with.
Thanks!