Data Analysis with Python Projects - Medical Data Visualizer

Tell us what’s happening:

My heat map doesn’t exacly match the expected heat map

Your code so far

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

1

df = pd.read_csv(‘medical_examination.csv’)

2

df[‘overweight’] = (df[‘weight’]/((df[‘height’]/100)**2)> 25).astype(int)

3

df[‘cholesterol’] = (df[‘cholesterol’]> 1).astype(int)
df[‘gluc’] = (df[‘gluc’]> 1).astype(int)

4

def draw_cat_plot():
# 5
df_cat = pd.melt(df, id_vars=[‘cardio’],
value_vars=[‘cholesterol’, ‘gluc’, ‘smoke’, ‘alco’, ‘active’, ‘overweight’],
var_name=‘variable’,
value_name=‘value’)

# 6
df_cat = df_cat.groupby(['cardio', 'variable', 'value']).size().reset_index(name='count')


# 7
g =sns.catplot(x='variable', hue='value', col='cardio', data=df_cat, kind='count')

g.set_axis_labels("variable", "total")



# 8
fig = g.figure



# 9
fig.savefig('catplot.png')
return fig

10

def draw_heat_map():
# 11

df_heat =df[
    (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))
]

# 12
corr = df_heat.corr()


# 13
mask = np.triu(np.ones_like(corr, dtype=bool))




# 14
fig, ax = plt.subplots(figsize=(10, 8))

# 15

sns.heatmap(corr, mask=mask, annot=True, cmap='magma', fmt='.1f', 
        square=True, linewidths=0.5, cbar_kws={"shrink": .8}, ax=ax)

# 16
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/127.0.0.0 Safari/537.36

Challenge Information:

Data Analysis with Python Projects - Medical Data Visualizer

the failure :
FAIL: test_heat_map_values (test_module.HeatMapTestCase.test_heat_map_values)

Traceback (most recent call last):
File “c:\Users\pc\OneDrive\Bureau\Data Analysis with Python\boilerplate-medical-data-visualizer\test_module.py”, line 47, in test_heat_map_values
self.assertEqual(actual, expected, “Expected different values in heat map.”)
AssertionError: Lists differ: [‘0.0[14 chars]0’, ‘-0.0’, ‘-0.1’, ‘0.5’, ‘0.0’, ‘0.1’, ‘0.1’[594 chars]0.1’] != [‘0.0[14 chars]0’, ‘0.0’, ‘-0.1’, ‘0.5’, ‘0.0’, ‘0.1’, ‘0.1’,[593 chars]0.1’]

First differing element 3:
‘-0.0’
‘0.0’

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


Ran 4 tests in 2.568s

FAILED (failures=1)

My heat map :

Expected hat map :

I would search the forum for solutions, this error has come up before:

https://forum.freecodecamp.org/search?q=Expected%20different%20values%20in%20heat%20map%20order%3Alatest_topic

1 Like

I hate my life, i looked through the forum, but skipped the one in italian, i thought i wouldn’t understand ! (df_heat[‘ap_lo’] <= df_heat[‘ap_hi’]) this was the missing line, i didn’t see it in the instructions I almost turned nuts, It was in the tasks :cry:

1 Like

Thanks pkdvalis, you’re a hero ! Not the one we deserve, the one we need ! :slight_smile:

1 Like

You did the work, glad you got it!

Sometimes, I like to paste all the instructions into the code and comment it so each block of code has the instruction commented with it. Helps to not miss anything.

1 Like