Tell us what’s happening:
hello I have been struggling for a while with this project, even though I ran the program on jupyter and the cat_plot and heat map are identical to the examples in replit
I still get 2 errors and 1 fail, I dont know what am I doing wrong
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['overweight']<=25,'overweight']=0
df.loc[df['overweight']>25,'overweight']=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'.
df_cat = pd.melt(df, id_vars='cardio', value_vars=['active','alco','cholesterol','gluc','overweight','smoke'])
# 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.
# Draw the catplot with 'sns.catplot()'
# Get the figure for the output
fig = sns.catplot(data=df_cat, x="variable",hue='value',col='cardio', kind="count")
# Do not modify the next two lines
fig.savefig('catplot.png')
return fig
# 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
matrix = np.triu(corr)
# Set up the matplotlib figure
# Draw the heatmap with 'sns.heatmap()'
x_axis_labels = ['id', 'age', 'sex', 'height', 'weight', 'ap_hi', 'ap_lo', 'cholesterol', 'gluc', 'smoke', 'alco', 'active', 'cardio', 'overweight'] # labels for x-axis
y_axis_labels = ['id', 'age', 'sex', 'height', 'weight', 'ap_hi', 'ap_lo', 'cholesterol', 'gluc', 'smoke', 'alco', 'active', 'cardio', 'overweight']
fig, ax = plt.subplots( figsize=(10,8) )
sns.heatmap(corr,mask = matrix,xticklabels=x_axis_labels, yticklabels=y_axis_labels,annot=True,fmt='0.1f')
# Do not modify the next two lines
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/106.0.0.0 Safari/537.36
Challenge: Data Analysis with Python Projects - Medical Data Visualizer
Link to the challenge:
these are the errors i get
this is the heatmap output on jupyter compared to the example on replit (as you can see they are both identical)
this is the heatmap output when i run the code on replit, the id column is entirely gone for some reason