0

I am working on a project and have to highlight the maximum correlations. By default df.corr() returns 1 for a row correlated to columns. While applying df.style.highlight_max(), I get ones highlighted instead of the real maximums.

I tried dropping the ones, but the entire row, or column got dropped.

I am novice.

Please help.

  • Welcome to StackOverflow. Please take the time to read this post on [how to provide a great pandas example](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) as well as how to provide a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve) and revise your question accordingly. These tips on [how to ask a good question](http://stackoverflow.com/help/how-to-ask) may also be useful. – jezrael Jul 11 '18 at 08:47

1 Answers1

0

You could use the replace function with NaN's (docs):

df.replace(1,np.nan)

Which will leave out the 1's in your matrix.

Alternatively, you could opt for the option to replace the diagonal values, instead of ones, which might be better when you expect perfectly correlated variables in your matrix, not located on the diagonal:

np.fill_diagonal(df.values, np.nan)
Jeroen
  • 857
  • 10
  • 18