【发布时间】:2017-11-07 08:39:28
【问题描述】:
我有一个数据框,想使用.style 突出显示第一列。
我不确定是否需要使用循环或函数
【问题讨论】:
标签: pandas dataframe colors styles
我有一个数据框,想使用.style 突出显示第一列。
我不确定是否需要使用循环或函数
【问题讨论】:
标签: pandas dataframe colors styles
你可以像这样在一行中解决它:
df.style.set_properties(**{'background-color': 'red'}, subset=['A'])
其中子集是要应用所需属性的列名列表。
结果与@jezrael 显示的相同 您可以检查其他属性和样式的可能性in pandas' website
【讨论】:
col_ref = {'A': 'background-color: red', 'C':'background-color:yellow'} \ df.style.apply(lambda x: pd.DataFrame(col_ref, index=df.index, columns=df.columns).fillna(''), axis=None)
【讨论】: