Skip to content Skip to sidebar Skip to footer

Apply Multiple Styles To A Data Frame Specific Column

I image that this might be a complex issue. I want to have five different colors for a specific column. cld_ght in the dataframe. Here is the dataframe: icao msg_type

Solution 1:

I think you can do with pd.cut:

def cloud_height_style_function(vals): 
    return pd.cut(vals, 
                  [-np.inf,200,500,1000,3000, np.inf], # need to review the bin a bit
                  labels=[f'color: {c}' for c in ['#9400D3','#FFA500','#FF0000','#FFFF00','#00b050']] 
                 )

df.style.apply(cloud_height_style_function,subset=['cld_hgt'])

Output:

enter image description here


Post a Comment for "Apply Multiple Styles To A Data Frame Specific Column"