Skip to content
Advertisement

How to highlight the column in Pandas Dataframe with MultiIndex / advanced indexing by the condition

Could you, please, help me with highlighting the columns in my dataframe with multiindex/advanced indexing?

I have the code which forms the Table 1:

JavaScript

So, (2022-02-27, ‘Разница в процентах’), (2022-02-26, ‘Разница в процентах’), etc. are columns in this table in python and ‘Источник’ is an index.

enter image description here

I want to highlight the columns, where the values >= 15, and make it red. Please, help me with that, because I can’t deal with multiindex well.

Advertisement

Answer

Multi-indexed columns can be accessed with tuples. e.g. pivot_clicks.loc[:, [("2022-02-27", 'Разница в процентах'), ("2022-02-26", 'Разница в процентах')]]

And working example for styling a single column:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement