Medical Data Visualizer heatmap error

Tell us what’s happening:

I’ve tried to run my code for the Medical Data Visualizer, but I keep getting the error that

Medical Data Visualizer

I’m trying to understand what’s wrong, but can’t find the reason behind the error

Your code so far

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np

# Import data
df = pd.read_csv("medical_examination.csv")

# Add 'overweight' column
df['overweight'] = (df['weight'] / (df['height'] / 100) ** 2).apply(lambda v: 0 if v < 25 else 1)

# Normalize data by making 0 always good and 1 always bad. If the value of 'cholestorol' or 'gluc' is 1, make the value 0. If the value is more than 1, make the value 1.
df["cholesterol"] = np.where(df["cholesterol"] > 1,1,0)
df["gluc"] = np.where(df["gluc"] > 1,1,0)

# Draw Categorical Plot
def draw_cat_plot():
   # Create DataFrame for cat plot using `pd.melt` using just the values from 'cholesterol', 'gluc', 'smoke', 'alco', 'active', and 'overweight'.
   df_cat = pd.melt(df,id_vars=["cardio"],value_vars=['cholesterol', 'gluc', 'smoke', 'alco', 'active', 'overweight'])
   df_cat["total"] = 1

   # Group and reformat the data to split it by 'cardio'. Show the counts of each feature. You will have to rename one of the collumns for the catplot to work correctly.
   df_cat = df_cat.groupby(['cardio','variable', 'value'], as_index=False).count()

   # Draw the catplot with 'sns.catplot()'
   g = sns.catplot(
     x = 'variable',
     y = 'total',
     col = 'cardio',
     hue = 'value',
     kind = 'bar',
     data = df_cat
   fig = g.fig

   # Do not modify the next two lines
   return fig

# Draw Heat Map
def draw_heat_map():
   # Clean the data
   df_heat = 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['weight'].quantile(0.025))) &
   (df['weight'] <= (df['weight'].quantile(0.975)))

   # Calculate the correlation matrix
   corr = df_heat.corr()

   # Generate a mask for the upper triangle
   mask = np.triu(corr)

   # Set up the matplotlib figure
   fig, ax= plt.subplots(figsize=(10,10))

   # Draw the heatmap with 'sns.heatmap()'
   ax = sns.heatmap(
     cbar_kws={'shrink':.45, 'format':'%.2f'}

   # Do not modify the next two lines
   return fig

Would appreciate some help with it.

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36 OPR/72.0.3815.320.

Challenge: Medical Data Visualizer

Link to the challenge:

There is an incompatibility between the test_heat_map_values() part of and different versions of matplotlib. Some versions of matplotlib produced some empty strings at the end of the list of heat map values and some do not. If you’ll edit and find the line expected = [...] in the test_heat_map_values() section and delete the three empty string items, it passes.

I had similar issue like yours.
I modified the test file to eliminate the error.