I am trying to mask a pandas data frame and pass it to create a heatmap. I have used the following code
import numpy as np
import pandas as pd
import seaborn as sns
df = pd.read_csv('distance_matrix_Mult_Align.csv', index_col=0)
mask = np.zeros_like(df)
triangle_indices = np.triu_indices_from(mask)
mask[triangle_indices] = True
sns.heatmap(df, cmap="RdBu", center=0, vmin=-1, vmax=1, mask=mask)
I get an error message saying ValueError: cannot convert float NaN to intege
.
To check for any NaN values, I run the following code
check_for_NaN = df.isnull().values.any()
print(check_for_NaN)
The output was False
. I found a post similar to mine (Pandas: ValueError: cannot convert float NaN to integer) but the dimensions of my dataframe is 640 × 640. So column-wise treatment seems impractical.
I am struggling to figure out the issue. I would really appreciate any help. Thanks!