Python Pandas - 在交互时突出显示列

时间:2017-08-10 13:27:44

标签: python pandas

我有一个由此代码生成的数据框:

hmdf = pd.DataFrame(hm01)
new_hm02 = hmdf[['FinancialYear','Month']]
new_hm01 = hmdf[['FinancialYear','Month','FirstReceivedDate']]

hm05 = new_hm01.pivot_table(index=['FinancialYear','Month'], aggfunc='count')
vals1 = ['April    ', 'May      ', 'June     ', 'July     ', 'August   ', 'September', 'October  ', 'November ', 'December ', 'January  ', 'February ', 'March    ']

df_hm = new_hm01.groupby(['Month', 'FinancialYear']).size().unstack(fill_value=0).rename(columns=lambda x: '{}'.format(x))
df_hml = df_hm.reindex(vals1)

我使用以下代码对其进行样式化,该代码在与之交互时突出显示一行。 但我希望它突出显示列而不是行

功能:

def hover(hover_color="#F1C40F"):
    return dict(selector="tr:hover",
                props=[("background-color", "%s" % hover_color)])

样式代码:

styles3 = [
    hover(),
    dict(selector="th", props=[("font-size", "80%"),
                               ("font-family", "Gill Sans MT"),
                               ("color",'white'),
                               ('background-color', 'rgb(11, 48, 79)'),
                               ("text-align", "center")]),
    dict(selector="td", props=[("font-size", "75%"),
                               ("font-family", "Gill Sans MT"),
                               ("text-align", "center")]),
    dict(selector="tr", props=[("line-height", "11px")]),
    dict(selector="caption", props=[("caption-side", "bottom")])
]



html3 = (dfPercent.style.set_table_styles(styles3)
            .set_caption(""))           

html3

输出:

enter image description here

有谁知道我需要做什么才能让它突出显示列而不是行?我已尝试将"tr:hover"更改为"td:hover"等,但它无法按我想要的方式工作

0 个答案:

没有答案