Conditionally format Python pandas cell

前端 未结 2 915
灰色年华
灰色年华 2020-11-28 15:16

I am trying to color, highlight, or change fond of Python pandas DataFrame based on the value of the cell. e.g. if the cells on each rows are bigger than the cell in the fir

2条回答
  •  温柔的废话
    2020-11-28 15:40

    import numpy as np
    import pandas as pd
    df = pd.DataFrame(np.random.rand(4,3))
    df.style.applymap(lambda x: 'background-color : yellow' if x>df.iloc[0,0] else '')
    

提交回复
热议问题