Tell us what’s happening:
Describe your issue in detail here.
Hello, I wrote some part of my code for this assignment. The Problem is that I can’t generate any graphs when I run the code. Can you help me to find why I can’t see any graphs or any errors at all when I run the code?
Your code so far
main.py
# This entrypoint file to be used in development. Start by reading README.md
import medical_data_visualizer
from unittest import main
# Test your function by calling it here
medical_data_visualizer.draw_cat_plot()
medical_data_visualizer.draw_heat_map()
# Run unit tests automatically
main(module='test_module', exit=False)
medical_data_visualizer.py
import pandas as pd #pandas
import seaborn as sns #seaborn
import matplotlib.pyplot as plt
import numpy as np
import math as math
# Import data
df = pd.read_csv('medical_examination.csv')
# Add 'overweight' column
value_num = df['weight'] / (df['height'] * df['height']) # I first tried math.sqrt which gave an error
# I ended up being too lazy to solve that error sooo, there u go
df['overweight'] = np.where(value_num > 25, 1, 0)
# 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['overweight'] = np.where((df['cholesterol'] == 1) | (df['gluc'] == 1), 0, 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'.
columns_to_melt = ['cholesterol', 'gluc', 'smoke', 'alco', 'active', 'overweight']
df_cat = pd.melt(df, value_vars=columns_to_melt)
# 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.
df_cat = df_cat.groupby(['cardio', 'variable', 'value']).size().reset_index(name='total')
df_cat.rename(columns={'value': 'feature_value'}, inplace=True)
# Draw the catplot with 'sns.catplot()'
plt.figure(figsize=(10, 6))
catplot = sns.catplot(x='variable', y='total', hue='feature_value', col='cardio', data=df_cat, kind='bar')
# Get the figure for the output
fig = catplot.fig
# 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 = None
# Calculate the correlation matrix
corr = None
# Generate a mask for the upper triangle
mask = None
# Set up the matplotlib figure
fig, ax = None
# Draw the heatmap with 'sns.heatmap()'
# Do not modify the next two lines
fig.savefig('heatmap.png')
return fig
Challenge: Data Analysis with Python Projects - Medical Data Visualizer
Link to the challenge: