小编EIn*_*ons的帖子

How to exclude the total row (margins) from styling (subset) in a pandas pivot table

I have a .pivot_table with margins = True.

I want to run .style.bar and .style.background_gradient on it but the problem is that margins (column totals) are also formatted and set to the maximum value so it looks non-descriptive.

I had a few ideas on how to solve this, however, none are working so far:

  1. Tried somehow excluding last row (the margins / total columns) from .style using subset, but failed.
  2. Saving the last row in a separate data frame. Removing …

python formatting pivot-table margins pandas

2
推荐指数
1
解决办法
1185
查看次数

标签 统计

formatting ×1

margins ×1

pandas ×1

pivot-table ×1

python ×1