Data Analysis with Python Projects - Medical Data Visualizer

Tell us what’s happening:

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 3.294s
FAILED (failures=1)

This is the error I am getting each time, I am unable to fix it as the table expects negative 0 values in some of the cells.

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')
Hieght = (df['height']*0.01)
Weight = df['weight']
BMI = Weight/(Hieght**2)
    


# 2
df['overweight'] = (BMI > 25).astype(int)
    
    

# 3
df['cholesterol'] = df['cholesterol'].apply(lambda x:0 if x == 1 else 1)
df['gluc'] = df['gluc'].apply(lambda x:0 if x == 1 else 1)





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


    # 6
    df_cat = df_melt
    

    # 7

    catplot = sns.catplot(x = "variable",hue = "value",col = 'cardio',kind ='count',data = df_cat)
    catplot.set_axis_labels("variable", "total")



    # 8
    fig = catplot.fig


    # 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
    heatmap = sns.heatmap(corr,mask = mask,fmt = '.1f', annot = True, cmap = 'coolwarm', linewidths = 0.5, 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/129.0.0.0 Safari/537.36

Challenge Information:

Data Analysis with Python Projects - Medical Data Visualizer

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

Thank you, i really appreciate your help, will keep it in mind.

Hi, and welcome to the forum :wave:

I believe you missed this step:

Clean the data. Filter out the following patient segments that represent incorrect data:

  • diastolic pressure is higher than systolic (Keep the correct data with (df[‘ap_lo’] <= df[‘ap_hi’]))

This error has come up a few times. I would suggest searching for vague errors like this in the forum:
https://forum.freecodecamp.org/search?q=AssertionError%3A%20Lists%20differ%20medical%20order%3Alatest_topic

Thank you very much it worked, will surely search it in the forum from now onwards.

1 Like