Heat map for medical data visualizer not testing correctly?

Hi there,

I have got through all of the data anaylsis with python course except for this one error I keep getting on this project that I cant solve.

FAIL: test_heat_map_values (test_module.HeatMapTestCase)

Traceback (most recent call last):
File “/home/runner/boilerplate-medical-data-visualizer-4/test_module.py”, line 47, in test_heat_map_values
self.assertEqual(actual, expected, “Expected differnt values in heat map.”)
AssertionError: Lists differ: [’’, ‘’, ‘’] != [‘0.0’, ‘0.0’, ‘-0.0’, ‘0.0’, ‘-0.1’, ‘0.5’[615 chars]0.1’]

First differing element 0:
‘’
‘0.0’

Second list contains 88 additional elements.
First extra element 3:
‘0.0’

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

It seems like the list the test produces for comparison is not populating with any values at all. I have tried for a few days now to solve it but I am completely stumped. My code for the heatmap is as follows:

 def draw_heat_map():

    # Clean the data
    dfclean = df[df['ap_lo'] <= df['ap_hi']]
    dfclean = dfclean[dfclean['height'] >= dfclean['height'].quantile(0.025)]
    dfclean = dfclean[dfclean['height'] <= dfclean['height'].quantile(0.975)]
    dfclean = dfclean[dfclean['weight'] >= dfclean['weight'].quantile(0.025)]
    dfclean = dfclean[dfclean['weight'] <= dfclean['weight'].quantile(0.975)]

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

    # Generate a mask for the upper triangle
    mask = np.triu(np.ones_like(corr, dtype=bool))


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

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


    # Do not modify the next two lines
    fig.savefig('heatmap.png')
    return fig

I would greatly appreciate any help with resolving this so I can finish the course!

The link to the repl.it project is: https://repl.it/@joewignell/boilerplate-medical-data-visualizer-4#medical_data_visualizer.py

Thanks in advance.

You need to put the data cleaning all in one single condition or else you will get wrong results.

Now looking at the error - you need to set annot=True in the heatmap, because right now it’s not showing values. Hence the list is empty.

I found when I ran the code on a Jupyter notebook I couldnt get correct values in a single query. I couldnt work out why but it seems t only accept 0 values for ap_lo and in fact returned what looked like the proper dataframe when I put ap_lo >= ap_hi which made no sense to me.