Issue
The following code snippet is supposed to show a heatmap of a dataset, like the first image:
colormap = plt.cm.RdBu
plt.figure(figsize=(18, 15))
plt.title('Pearson Correlation of Features', y=1.05, size=50)
sns.heatmap(df.corr(), linewidths=0.1, vmax=1.0, square=True, cmap=colormap, linecolor='white', annot=True)
plt.show()
However, my RdBu
is highlighted in PyCharm and the warning message says:
Cannot find reference 'RdBu' in 'cm.py'
There are a few posts that basically show the syntax is correct and I am not missing any packages. What am I doing wrong here that I get this empty map instead?
Solution
I was missing the following code before the graph code:
for c in df.columns:
if df[c].dtype == 'object':
lbl = LabelEncoder()
lbl.fit(list(df[c].values))
df[c] = lbl.transform(list(df[c].values))
Answered By - CatarinaRuna
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.