Medical data visualizer Error

Hi everybody! I think I’m almost done with this project, but it keeps giving me an error I don’t understand. Can someone please help me. This is my code:

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", header=0)

# Add 'overweight' column
df['overweight'] = (df['weight']/((df['height']/100)**2))>25 # adds column to df with BMI bool
df['overweight'] = df['overweight'].astype(int)

# 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['cholesterol'] = df['cholesterol'] > 1
df['cholesterol'] = df['cholesterol'].astype(int)
df['gluc'] = df['gluc'] > 1
df['gluc'] = df['gluc'].astype(int)

# 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=["cholesterol", "gluc", "smoke", "alco", "active", "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.
  df_cat = pd.DataFrame(df_cat.groupby(["cardio","variable","value"], as_index=True)["value"].count()).rename(columns={"value":"total"}).reset_index()
    

  fig = sns.catplot(x="variable", y="total", col="cardio", hue="value", data=df_cat, kind="bar").fig
  
  # Do not modify the next two lines
  fig.savefig('catplot.png')
  return fig

# Filter out the following patient segments that represent incorrect data: 

drop_bp = df[(df['ap_lo'] > df['ap_hi'])]
df.drop(drop_bp.index, inplace=True)

drop_height1 = df[(df['height'] < df['height'].quantile(0.025))]
df.drop(drop_height1.index, inplace=True)

drop_height2 = df[(df['height'] <= df['height'].quantile(0.975))]
df.drop(drop_height2.index, inplace=True)

drop_weight1 = df[(df['weight'] >= df['weight'].quantile(0.025))]
df.drop(drop_weight1.index, inplace=True)

drop_weight2 = df[(df['weight'] <= df['weight'].quantile(0.975))]
df.drop(drop_weight2.index, inplace=True)

# Draw Heat Map
def draw_heat_map():
    # Clean the data

    # Calculate the correlation matrix
  corr = df.corr()

    # Generate a mask for the upper triangle
  mask = np.zeros_like(corr, dtype=bool)
  mask[np.triu_indices_from(mask)] = True

  
  # Set up the matplotlib figure
  fig, ax = plt.subplots(figsize=(13, 10))
  
  # Draw the heatmap with 'sns.heatmap()'
  sns.heatmap(corr, annot=True, cmap="YlGnBu", mask=mask, linewidths=.5, vmin = -.16, vmax = .32, fmt=".1f", center=0)


    # Do not modify the next two lines
  fig.savefig('heatmap.png')
  return fig

And this is the error that keeps showing up in Replit:

Traceback (most recent call last):
File “/home/runner/Jims-medical-data-visualizer/main.py”, line 6, in
medical_data_visualizer.draw_cat_plot()
File “/home/runner/Jims-medical-data-visualizer/medical_data_visualizer.py”, line 30, in draw_cat_plot
fig = sns.catplot(x=“variable”, y=“total”, col=“cardio”, hue=“value”, data=df_cat, kind=“bar”).fig
File “/home/runner/Jims-medical-data-visualizer/venv/lib/python3.10/site-packages/seaborn/categorical.py”, line 3211, in catplot
p.establish_colors(color, palette, 1)
File “/home/runner/Jims-medical-data-visualizer/venv/lib/python3.10/site-packages/seaborn/categorical.py”, line 707, in establish_colors
lum = min(light_vals) * .6
ValueError: min() arg is an empty sequence
exit status 1

I just finished and submitted this assignment like an hour ago, so was really hoping I could help, but it seems to be an issue with the code in seaborn… Found this link on stack overflow… maybe check with seaborn version your replit has installed and see if its this bug:

Hopefully someone else maybe has seen this before.

Also, at one point I did start getting some errors that looked like it had to do with other modules, but errors didn’t reoccur after closing out and re-accessing the project… maybe its a replit issue.

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