Python seaborn heatmap annotation after masking

I am creating a Seaborn heatmap with a given pandas framework which has numbers and nan. Something like that:

1 2 nan
4 nan nan
nan nan nan

      

I need a hot map to be annotated and I also need to mask / gray out all nans. I found a mask function and can use it like this:

mask = df.isnull()

      

Then I can create a heatmap like this:

sns.heatmap(df, mask = mask, annot = True, fmt = "g", cmap = "Blues")

      

The problem is that with the mask, it seems like the nan are converted to strings while the numbers remain as floats. I am getting the following exception:

ValueError: unknown format code 'g' for object of type 'str'

Something like this happens (partial plot before it throws an exception):

enter image description here

As you can tell, the first formatted cell is fine as it is floating point, but then when it hits the nano that is masked it seems like it is not a string and cannot be formatted.

Does anyone have any suggestions on how to comment on non-oiled data only?

thank

+3
python plot visualization heatmap seaborn


source to share


No one has answered this question yet

Check out similar questions:

5504
Does Python have a ternary conditional operator?
5231
What are metaclasses in Python?
4473
Calling an external command in Python
3790
How can I safely create a subdirectory?
3602
Does Python have a substring method "contains"?
3119
What is the difference between Python list methods that are appended and expanded?
2818
Finding the index of an element by specifying the list that contains it in Python
2601
How can I make a time delay in Python?
2568
How to find the current time in Python
0
generate heatmap from dataframe using python and seaborn



All Articles
Loading...
X
Show
Funny
Dev
Pics