2

Given the following data frame and pivot table:

import pandas as pd df=pd.DataFrame({'A':['a','a','a','a','a','b','b','b','b'], 'B':['x','y','z','x','y','z','x','y','z'], 'C':['a','b','a','b','a','b','a','b','a'], 'D':[7,5,3,4,1,6,5,3,1]}) table = pd.pivot_table(df, index=['A', 'B','C'],aggfunc='sum') table D A B C a x a 7 b 4 y a 1 b 5 z a 3 b x a 5 y b 3 z a 1 b 6 

I'd like to create a heat map with divisions per indices A and B like this:

enter image description here

Is it possible?

1 Answer 1

3

You can use Styler in jupyter notebook, see docs and notebook:

import seaborn as sns import pandas as pd df=pd.DataFrame({'A':['a','a','a','a','a','b','b','b','b'], 'B':['x','y','z','x','y','z','x','y','z'], 'C':['a','b','a','b','a','b','a','b','a'], 'D':[7,5,3,4,1,6,5,3,1]}) table = pd.pivot_table(df, index=['A', 'B','C'],aggfunc='sum') table cm = sns.light_palette("blue", as_cmap=True) s = df.reset_index().style.background_gradient(cmap=cm) s 

heatmap

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! Can you tell me how I can export it as a Seaborn Heatmap or something cleaner-looking like my sample?
Ok, you can try open Jupyter notebook. for me it open new tab in browser. Then you can create new notebook (right up) and it is possible download as html, pdf, rst...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.