Data Analysis with Python Projects - Medical Data Visualizer

Tell us what’s happening:
I have reviewed the forum but I can’t seem to find the answer. This is the error I’m getting:

FAIL: test_heat_map_values (test_module.HeatMapTestCase)

Traceback (most recent call last):
File “/home/runner/boilerplate-medical-data-visualizer/”, line 47, in test_heat_map_values
self.assertEqual(actual, expected, “Expected different values in heat map.”)
AssertionError: Lists differ: [‘0.0025’, ‘0.0034’, ‘-0.018’, ‘0.00033’, ‘-0.[795 chars].14’] != [‘0.0’, ‘0.0’, ‘-0.0’, ‘0.0’, ‘-0.1’, ‘0.5’, ‘[612 chars]0.1’]

First differing element 0:

Diff is 2250 characters long. Set self.maxDiff to None to see it. : Expected different values in heat map.

Ran 4 tests in 6.473s

FAILED (failures=1)

Describe your issue in detail here.

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

pd.set_option(‘display.max_columns’, None)
bmi = df[‘weight’] /( (df[‘height’]/100)**2)
df[‘overweight’] = np.where(bmi > 25, 1, 0)

Normalize data by making 0 always good and 1 always bad. If the value of ‘cholesterol’ 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, 0,1)
df[“gluc”] = np.where(df[“gluc”] == 1, 0,1)

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’])
# Group and reformat the data to split it by ‘cardio’. Show the counts of each feature. You will have to rename one of the columns for the catplot to work correctly.
df_cat = df_cat.groupby([‘cardio’, ‘variable’]).value_counts()
df_cat = df_cat.reset_index()
df_cat.columns = [‘cardio’, ‘variable’, ‘value’, ‘total’]

# Draw the catplot with 'sns.catplot()'

my_plot = sns.catplot(data=df_cat, x='variable', y='total', col='cardio', kind = 'bar', hue = 'value')

# Get the figure for the output
fig = my_plot.fig

# Do not modify the next two lines
return fig

Draw Heat Map

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[‘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(np.ones_like(df_heat.corr(), dtype=bool))

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

# Draw the heatmap with 'sns.heatmap()'
sns.heatmap(corr, mask = mask, annot=True)

# Do not modify the next two lines
return fig

Thank you in advance for the assistance

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Data Analysis with Python Projects - Medical Data Visualizer

Link to the challenge:

This means your results are not rounded/formatted correctly. The documentation for sns.heatmap() can help you with that.

Thank you for your help on this. I was staring at this problem for quite a while.