Tell us what’s happening:
I’m trying to get the first chart (catplot) done, but I’m struggling. What’s strange is that, on my computer, the test module doesn’t complain about anything (the test runs OK), but on replit.com I get this error:
FAIL: test_bar_plot_number_of_bars (test_module.CatPlotTestCase.test_bar_plot_number_of_bars)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-medical-data-visualizer/test_module.py", line 28, in test_bar_plot_number_of_bars
self.assertEqual(actual, expected, "Expected a different number of bars chart.")
AssertionError: 15 != 13 : Expected a different number of bars chart.
Your code so far
def draw_cat_plot():
# 5
df_cat = pd.melt(df,
id_vars='cardio',
value_vars=[
'active', 'alco', 'cholesterol', 'gluc', 'overweight',
'smoke'
])
# 6
df_cat = df_cat.groupby(['cardio', 'variable',
'value']).size().reset_index(name='total')
# 7
cardio0 = df_cat[df_cat['cardio'] == 0]
cardio1 = df_cat[df_cat['cardio'] == 1]
# 8
fig, axs = plt.subplots(ncols=2, figsize=(15, 5))
sns.countplot(data=cardio0, x='variable', hue='value',
ax=axs[0]).set(title='cadio = 0', ylabel="total")
axs[0].legend([], [], frameon=False)
sns.countplot(data=cardio1, x='variable', hue='value',
ax=axs[1]).set(title='cadio = 1', ylabel="total")
sns.move_legend(axs[1], "right", bbox_to_anchor=(1.15, 0.5))
# 9
fig.savefig('catplot.png')
return fig
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:129.0) Gecko/20100101 Firefox/129.0
Challenge Information:
Data Analysis with Python Projects - Medical Data Visualizer