I am having this error and can’t find the solution. Does anyone knows how to fix it? Thanks in advance.
EE.['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', '', '', '']
.
======================================================================
ERROR: test_bar_plot_number_of_bars (test_module.CatPlotTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-medical-data-visualizer-3/test_module.py", line 26, in test_bar_plot_number_of_bars
actual = len([rect for rect in self.ax.get_children() if isinstance(rect, mpl.patches.Rectangle)])
AttributeError: 'numpy.ndarray' object has no attribute 'get_children'
======================================================================
ERROR: test_line_plot_labels (test_module.CatPlotTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-medical-data-visualizer-3/test_module.py", line 13, in test_line_plot_labels
actual = self.ax.get_xlabel()
AttributeError: 'numpy.ndarray' object has no attribute 'get_xlabel'
----------------------------------------------------------------------
Ran 4 tests in 22.332s
FAILED (errors=2)
CODE:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
# Import data
df = df = pd.read_csv('medical_examination.csv')
# 'overweight' column
bmi = df['weight'] / pow((df['height'] / 100), 2)
df['overweight'] = bmi
df.loc[bmi <= 25, 'overweight'] = 0
df.loc[bmi > 25, 'overweight'] = 1
# Normalize data
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'.
df_cat = pd.melt(
df,
id_vars='cardio',
value_vars=[
'active', 'alco', 'cholesterol', 'gluc', 'overweight', 'smoke'
])
sns.set(font_scale=3)
sns.set_style("white")
fig = sns.catplot(
x='variable',
hue='value',
kind='count',
palette='colorblind',
col='cardio',
edgecolor='.01',
data=df_cat,
height=10,
aspect=2)
fig.savefig('catplot.png')
return fig
# Heat Map
def draw_heat_map():
df_heat = 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)))]
corr = df_heat.corr()
mask = np.triu(corr)
fig, ax = plt.subplots(figsize=(15, 10))
sns.set(font_scale=1.4)
sns.heatmap(
corr,
vmax=.30,
center=0.08,
annot=True,
fmt='.1f',
cbar=True,
square=True,
mask=mask)
fig.savefig('heatmap.png')
return fig