Data Analysis with Python Projects - Medical Data Visualizer

Tell us what’s happening:
Describe your issue in detail here.
When ran on my local computer, my code past the test. When ran on replit.com, it failed to pass because some strange empty strings are added.

Your code so far

import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np

# Import data
df = pd.read_csv("medical_examination.csv")

# Add 'overweight' column
df['overweight'] = df["overweight"] = (df["weight"] /
                                       (df["height"] / 100)**2 > 25) * 1

# 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) * 1
df["gluc"] = (df["gluc"] > 1) * 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 = df.melt(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 = df_cat.groupby(["cardio",
                           "variable"]).count().sort_index().reset_index()
  df_cat.rename({"value": "total"}, axis=1, inplace=True)

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

  # Get the figure for the output
  g = sns.catplot(data=df_cat,
                  x="variable",
                  y="total",
                  hue="cardio",
                  col="cardio",
                  kind="bar")
  fig = g.axes[0][0].get_figure()

  # 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.loc[(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
  mask = np.triu(np.ones_like(corr))

  # Set up the matplotlib figure
  fig, ax = plt.subplots(figsize=(11, 9))

  # Draw the heatmap with 'sns.heatmap()'
  sns.heatmap(corr, mask=mask, annot=True, fmt=".1f", ax=ax)

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

On replit.com, the error message is below:

======================================================================
FAIL: test_heat_map_values (test_module.HeatMapTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-medical-data-visualizer/test_module.py", line 47, in test_heat_map_values
    self.assertEqual(actual, expected, "Expected different values in heat map.")
AssertionError: Lists differ: ['0.0[607 chars] '0.2', '0.1', '0.1', '-0.0', '0.0', '-0.0', '0.1', '', '', ''] != ['0.0[607 chars] '0.2', '0.1', '0.1', '-0.0', '0.0', '-0.0', '0.1']

First list contains 3 additional elements.
First extra element 91:
''

Diff is 989 characters long. Set self.maxDiff to None to see it. : Expected different values in heat map.

----------------------------------------------------------------------

On my local computer, below is the result:

.['0.0', '0.0', '-0.0', '0.0', '-0.1', '0.5', '0.0', '0.1', '0.1', '0.3', '0.0', '0.0', '0.0', '0.0', '0.0', '0.0', '0.2', '0.1', '0.0', '0.2', '0.1', '0.0', '0.1', '-0.0', '-0.1', '0.1', '0.0', '0.2', '0.0', '0.1', '-0.0', '-0.0', '0.1', '0.0', '0.1', '0.4', '-0.0', '-0.0', '0.3', '0.2', '0.1', '-0.0', '0.0', '0.0', '-0.0', '-0.0', '-0.0', '0.2', '0.1', '0.1', '0.0', '0.0', '0.0', '0.0', '0.3', '0.0', '-0.0', '0.0', '-0.0', '-0.0', '-0.0', '0.0', '0.0', '-0.0', '0.0', '0.0', '0.0', '0.2', '0.0', '-0.0', '0.2', '0.1', '0.3', '0.2', '0.1', '-0.0', '-0.0', '-0.0', '-0.0', '0.1', '-0.1', '-0.1', '0.7', '0.0', '0.2', '0.1', '0.1', '-0.0', '0.0', '-0.0', '0.1']
.
----------------------------------------------------------------------
Ran 4 tests in 1.211s

Below is the replit.com link for this:
boilerplate-medical-data-visualizer - Replit
Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:108.0) Gecko/20100101 Firefox/108.0

Challenge: Data Analysis with Python Projects - Medical Data Visualizer

Link to the challenge:

It’s the same problem as here.

Thank you. I have figured out one way to solve it for my other problems, which your link pointed to. But that doesn’t work for this problem.

It does. I forked and tested your project earlier and ran the tests without these errors on replit. The empty array elements indicates version mismatches in the dependencies and is a well documented problem with this project in the forums. All of the python data analysis projects should use the same techniques to update the python version and the project dependencies before testing.

May you tell me how you fix this? I tried many ways listed in the forum. Just failed one after another. It is really frustrating.

I am sorry I keep raising this up and bothering you. I tried five or six ways in the forum to solve this bug. All these tries and fails just make me more and more frustrating.

If anyone have the same dependency problem, please refer to here.

Important

Use the package managing tools in replit.com to uninstall seaborn and pandas and reinstall them to the latest version. Only editing the related files may not work.
The above solution works for me.

thanks it really works

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