Data Analysis with Python Projects - Medical Data Visualizer

Tell us what’s happening:
hello I have completed all the tasks for the medical data visualization project and it works on jupyter notebook but when I run the code in replit it gives me 2 errors, is something wrong with my code?

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',index_col='id')
# Add 'overweight' column
df['overweight'] = df['weight']/((df['height']/100)**2)
# 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.loc[df["cholesterol"] == 1, "cholesterol"] = 0
df.loc[df["cholesterol"] > 1, "cholesterol"] = 1
df.loc[df["gluc"] == 1, "gluc"] = 0
df.loc[df["gluc"] > 1, "gluc"] = 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'.

    # 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.
    tot = pd.melt(df, id_vars='cardio', value_vars=['active','alco','cholesterol','gluc','overweight','smoke'])

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

    # Get the figure for the output
    fig = sns.catplot(data=tot, x="variable",hue='value',col='cardio', kind="count")

    # Do not modify the next two lines
    return fig

# Draw Heat Map
def draw_heat_map():
    # Clean the data
    ko = 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))].index

    # Calculate the correlation matrix
    corr = df.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(figsize=(10,8)) 

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

    # Do not modify the next two lines
    return fig

Your browser information:

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

Challenge: Data Analysis with Python Projects - Medical Data Visualizer

Link to the challenge:

this is the error i get

This bit stores the result of sns.catplot() in fig. sns.catplot() returns a FacetGrid object and the tests expect a matplotlib Figure in fig, so you’ll need to consult the documentation for each and sort out how to return the appropriate object. There are other threads in the forum with this issue if you’ll search for them.

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