SOMEBODY PLEASE :
I have tried it all, i run my code personally on my pc using jupyterlab before running it on gitpod (interface provided by freecodecamp). All ran successfully, only to get to gitpod and they all failed, this is my code for the project ’ Medical Data Visualizer’.
Kindly tell me what i am doing wrong here…
Your code so far (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')
# Add 'overweight' column
BMI = (df['weight'] / (df['height']/100)**2)
def change(i):
if i > 25:
return 1
else:
return 0
df['overweight'] = BMI.apply(change)
# 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.
normalized_change = {1:0, 2:1, 3:1}
df['cholesterol'] = df['cholesterol'].map(normalized_change)
df['gluc'] = df['gluc'].map(normalized_change)
# 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', 'alco', 'active', 'smoke', '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']).size().reset_index(name='total'))
# Draw the catplot with 'sns.catplot()'
sns.catplot(data=df_cat, x="variable", y="total", hue="value", col="cardio", kind="bar", order=["active", "alco", "cholesterol", "gluc", "overweight", "smoke"])
# Get the figure for the output
fig = sns.catplot(data=df_cat, x="variable", y="total", hue="value", col="cardio", kind="bar", order=["active", "alco", "cholesterol", "gluc", "overweight", "smoke"]).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 = 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
mask = np.zeros_like(corr)
mask[np.triu_indices_from(mask)] = True
# Set up the matplotlib figure
fig, ax = plt.subplots()
# Draw the heatmap with 'sns.heatmap()'
ax = sns.heatmap(corr, mask=mask, vmax=0.32, vmin = -0.16, square=True, fmt="0.1f", annot=True)
# Do not modify the next two lines
fig.savefig('heatmap.png')
return fig
After running my main.py… This is the error it gave me
gitpod /workspace/boilerplate-medical-data-visualizer (main) $ /home/gitpod/.pyenv/shims/python /workspace/boilerplate-medical-data-visualizer/main.py
Traceback (most recent call last):
File "/workspace/boilerplate-medical-data-visualizer/main.py", line 6, in <module>
medical_data_visualizer.draw_cat_plot()
File "/workspace/boilerplate-medical-data-visualizer/medical_data_visualizer.py", line 39, in draw_cat_plot
sns.catplot(data=df_cat, x="variable", y="total", hue="value", col="cardio", kind="bar", order=["active", "alco", "cholesterol", "gluc", "overweight", "smoke"])
File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/seaborn/categorical.py", line 3716, in catplot
p.establish_variables(x_, y_, hue, data, orient, order, hue_order)
File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/seaborn/categorical.py", line 158, in establish_variables
orient = self.infer_orient(x, y, orient)
File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/seaborn/categorical.py", line 359, in infer_orient
elif is_not_numeric(y):
File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/seaborn/categorical.py", line 339, in is_not_numeric
np.asarray(s, dtype=np.float)
File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/numpy/__init__.py", line 305, in __getattr__
raise AttributeError(__former_attrs__[attr])
AttributeError: module 'numpy' has no attribute 'float'.
`np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
http:numpy.org/devdocs/release/1.20.0-notes.html#deprecations
gitpod /workspace/boilerplate-medical-data-visualizer (main) $
*And after running my test_module.py.. It gave me the following errors..*
***gitpod /workspace/boilerplate-medical-data-visualizer (main) $ /home/gitpod/.pyenv/shims/python /workspace/boilerplate-medical-data-visualizer/test_module.py**
**EE/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/seaborn/matrix.py:80: FutureWarning: In the future `np.bool` will be defined as the corresponding NumPy scalar.**
** dtype=np.bool)**
**E/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/seaborn/matrix.py:80: FutureWarning: In the future `np.bool` will be defined as the corresponding NumPy scalar.**
** dtype=np.bool)***
E
======================================================================
ERROR: test_bar_plot_number_of_bars (__main__.CatPlotTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/workspace/boilerplate-medical-data-visualizer/test_module.py", line 9, in setUp
self.fig = medical_data_visualizer.draw_cat_plot()
File "/workspace/boilerplate-medical-data-visualizer/medical_data_visualizer.py", line 39, in draw_cat_plot
sns.catplot(data=df_cat, x="variable", y="total", hue="value", col="cardio", kind="bar", order=["active", "alco", "cholesterol", "gluc", "overweight", "smoke"])
File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/seaborn/categorical.py", line 3716, in catplot
p.establish_variables(x_, y_, hue, data, orient, order, hue_order)
File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/seaborn/categorical.py", line 158, in establish_variables
orient = self.infer_orient(x, y, orient)
File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/seaborn/categorical.py", line 359, in infer_orient
elif is_not_numeric(y):
File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/seaborn/categorical.py", line 339, in is_not_numeric
np.asarray(s, dtype=np.float)
File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/numpy/__init__.py", line 305, in __getattr__
raise AttributeError(__former_attrs__[attr])
AttributeError: module 'numpy' has no attribute 'float'.
`np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https:/numpy.org/devdocs/release/1.20.0-notes.html#deprecations
======================================================================
ERROR: test_line_plot_labels (__main__.CatPlotTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/workspace/boilerplate-medical-data-visualizer/test_module.py", line 9, in setUp
self.fig = medical_data_visualizer.draw_cat_plot()
File "/workspace/boilerplate-medical-data-visualizer/medical_data_visualizer.py", line 39, in draw_cat_plot
sns.catplot(data=df_cat, x="variable", y="total", hue="value", col="cardio", kind="bar", order=["active", "alco", "cholesterol", "gluc", "overweight", "smoke"])
File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/seaborn/categorical.py", line 3716, in catplot
p.establish_variables(x_, y_, hue, data, orient, order, hue_order)
File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/seaborn/categorical.py", line 158, in establish_variables
orient = self.infer_orient(x, y, orient)
File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/seaborn/categorical.py", line 359, in infer_orient
elif is_not_numeric(y):
File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/seaborn/categorical.py", line 339, in is_not_numeric
np.asarray(s, dtype=np.float)
File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/numpy/__init__.py", line 305, in __getattr__
raise AttributeError(__former_attrs__[attr])
AttributeError: module 'numpy' has no attribute 'float'.
`np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https:/numpy.org/devdocs/release/1.20.0-notes.html#deprecations
======================================================================
ERROR: test_heat_map_labels (__main__.HeatMapTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/workspace/boilerplate-medical-data-visualizer/test_module.py", line 33, in setUp
self.fig = medical_data_visualizer.draw_heat_map()
File "/workspace/boilerplate-medical-data-visualizer/medical_data_visualizer.py", line 73, in draw_heat_map
ax = sns.heatmap(corr, mask=mask, vmax=0.32, vmin = -0.16, square=True, fmt="0.1f", annot=True)
File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/seaborn/matrix.py", line 515, in heatmap
plotter = _HeatMapper(data, vmin, vmax, cmap, center, robust, annot, fmt,
File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/seaborn/matrix.py", line 113, in __init__
mask = _matrix_mask(data, mask)
File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/seaborn/matrix.py", line 80, in _matrix_mask
dtype=np.bool)
File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/numpy/__init__.py", line 305, in __getattr__
raise AttributeError(__former_attrs__[attr])
AttributeError: module 'numpy' has no attribute 'bool'.
`np.bool` was a deprecated alias for the builtin `bool`. To avoid this error in existing code, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https:/numpy.org/devdocs/release/1.20.0-notes.html#deprecations
======================================================================
ERROR: test_heat_map_values (__main__.HeatMapTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/workspace/boilerplate-medical-data-visualizer/test_module.py", line 33, in setUp
self.fig = medical_data_visualizer.draw_heat_map()
File "/workspace/boilerplate-medical-data-visualizer/medical_data_visualizer.py", line 73, in draw_heat_map
ax = sns.heatmap(corr, mask=mask, vmax=0.32, vmin = -0.16, square=True, fmt="0.1f", annot=True)
File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/seaborn/matrix.py", line 515, in heatmap
plotter = _HeatMapper(data, vmin, vmax, cmap, center, robust, annot, fmt,
File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/seaborn/matrix.py", line 113, in __init__
mask = _matrix_mask(data, mask)
File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/seaborn/matrix.py", line 80, in _matrix_mask
dtype=np.bool)
File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/numpy/__init__.py", line 305, in __getattr__
raise AttributeError(__former_attrs__[attr])
AttributeError: module 'numpy' has no attribute 'bool'.
`np.bool` was a deprecated alias for the builtin `bool`. To avoid this error in existing code, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https:/numpy.org/devdocs/release/1.20.0-notes.html#deprecations
----------------------------------------------------------------------
Ran 4 tests in 0.174s
FAILED (errors=4)
SOMEBODY PLEASE HELP. THANKS.
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Challenge Information:
Data Analysis with Python Projects - Medical Data Visualizer