For some reason i dont understand my results for the heat map are completely wrong. As far as i know the representation part of the function shouldnt chage the dataframe and neither does the bar representation. The error has to be in the clean the data section but after revising and changing the mask i havent found the bug/error. Anyway this is my code for the heatmap function:
def draw_heat_map():
# Clean the data
df_heat = df[
(df['ap_lo'] <= df['ap_hi']) &
(df['height'] >= df['height'].quantile(0.025)) &
(df['height'] <= df['height'].quantile(0.975)) &
(df['weight'] >= df['height'].quantile(0.025)) &
(df['weight'] <= df['height'].quantile(0.975))]
# Calculate the correlation matrix
corr = df_heat.corr()
# Generate a mask for the upper triangle
mask = np.triu(corr)
#Triu is a numpy method that returns the upper triangle of a matrix. It returns a new matrix with the elements below the diagonal set to 0. Tril does the same but for the lower triangle.
# Set up the matplotlib figure
fig, ax = plt.subplots(figsize=(12,12))
# Draw the heatmap with 'sns.heatmap()'
sns.heatmap(corr, linewidths=1, annot=True, square=True, mask=mask, fmt=".1f", center=0.08, cbar_kws = {"shrink":0.5} )
# Do not modify the next two lines
fig.savefig('heatmap.png')
return fig
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 OPR/106.0.0.0
Challenge Information:
Data Analysis with Python Projects - Medical Data Visualizer