Data Analysis with Python Projects - Medical Data Visualizer

Tell us what’s happening:
I am having trouble filling my heatmap with values. When I look at the heatmap my code generates, it does not have the values inside of the squares. I did the annot=True in my code but it still does not appear in the figure. Am I missing something?

Your code so far

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(corr)

# Set up the matplotlib figure

fig, ax = plt.subplots(figsize=(12,12))

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

sns.heatmap(data=corr,annot=True,mask=mask, linewidths=1, square=True, fmt=‘.1f’, center= 0.08, cbar_kws= {‘shrink’:0.5}).figure

# Do not modify the next two lines

fig.savefig(‘heatmap.png’)
return fig

My figure:

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 Edg/117.0.2045.41

Challenge: Data Analysis with Python Projects - Medical Data Visualizer

Link to the challenge:

If you run the tests, do they come up with an error? It sounds like this problem:

https://forum.freecodecamp.org/t/data-analysis-with-python-projects-medical-data-visualizer-heatmap-values/639407

Which you can solve by forking the boilerplate code from here: https://replit.com/@pkdvalis/fcc-2023-Boilerplate-medical-data-visualizer and pasting your code into it.

It could be a different problem, would need to investigate a bit more. I would run the tests first and see if it generates the same error.

1 Like

I tried pasting my code into the boilerplate code and still came up with errors. This is a link to my code: boilerplate-medical-data-visualizer - Replit

For reference here are the errors that I am receiving:

======================================================================
FAIL: test_heat_map_values (test_module.HeatMapTestCase)

Traceback (most recent call last):
File “/home/runner/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: [‘–’, ‘–’, ‘–’, ‘–’, ‘–’, ‘–’, ‘–’, [36 chars]‘–’] != [‘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 77 additional elements.
First extra element 14:
‘0.0’

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


I’m not able to run or load anything on Replit right now, I’ll try it again later. Experience there has been degrading a lot recently but it is free so…

Can you confirm where you forked the boilerplate from? The working one I linked is called “fcc-2023-Boilerplate-medical-data-visualizer” and your replit is called “boilerplate-medical-data-visualizer” with a lowercase ‘b’ so it seems like it’s different.

It’s important because I’m not sure what actually causes the “[‘–’, ‘–’, ‘–’,” error, but I suspect it might be some kind of replit corruption or dependency. If you fork this one:

https://replit.com/@pkdvalis/fcc-2023-Boilerplate-medical-data-visualizer

It has been proven to work

However, this is only to solve your 3rd error here " FAIL: test_heat_map_values" The first two errors might be code related. It would be nice if we could see some values first, though.

Good news is that I fixed the first two errors and values show up in the heatmap. That original link is my original code. Here is the link with the code that I forked: (fcc-2023-Boilerplate-medical-data-visualizer (1) - Replit)). Values pop up in my heatmap but I am still getting the error : raceback (most recent call last):
File “/home/runner/fcc-2023-Boilerplate-medical-data-visualizer-928/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[59 chars], ‘0.2’, ‘0.0’, ‘0.0’, ‘0.0’, ‘0.0’, ‘0.0’, ‘0[548 chars]0.1’] != ['0.0[59 chars], ‘0.3’, ‘0.0’, ‘0.0’, ‘0.0’, ‘0.0’, ‘0.0’, ‘0[548 chars]0.1’]

First differing element 9:
‘0.2’
‘0.3’

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

1 Like

Great, you’re almost there!

You need to examine the section of your code implementing this part of the Instructions:

Clean the data. Filter out the following patient segments that represent incorrect data: 
height is less than the 2.5th percentile (Keep the correct data with (df['height'] >= df['height'].quantile(0.025)))
height is more than the 97.5th percentile
weight is less than the 2.5th percentile
weight is more than the 97.5th percentile
1 Like

Thank you for your help! All tests passed now :slight_smile:

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.