Medical Data Visualizer issues with bar count chart


Hi,
I am trying to work out two failed tests:
Reasons:

  1. Expected a different number of bars chart.
  2. Expected line plot xlabel to be ‘variable’

Here is how my code looks leading up to the bar chart.
First normalizing values:
df[‘cholesterol’] = np.where(df[‘cholesterol’] > 1, 1, 0)

df[‘gluc’] = np.where(df[‘gluc’] > 1, 1, 0)

Using melt to change the shape of my df:
df_cat = pd.melt(df, id_vars=[‘cardio’], value_vars=[‘active’, ‘alco’, ‘cholesterol’, ‘gluc’, ‘overweight’, ‘smoke’])

And finally drawing the plot.

fig, ax = plt.subplots(figsize=(16, 12))
g = sns.catplot(data=df_cat, kind= ‘count’, x= ‘variable’, hue=‘value’, col=‘cardio’, y= None)

I appreciate any tips to fix this issue.

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36.

Challenge: Medical Data Visualizer

Link to the challenge:

1 Like

I have a very similar issue, although I am only using one line to generate the bar chart.

fig = sns.catplot(x=“variable”, hue=“value”, col=“cardio”, data=grouped_df_cat, kind=“count”, height=10, aspect=1.5)

It is generating the two bar charts for cardio=0 and cardio=1, however the ranger in the y-axis is 0 to 1, i.e. it is using the value rather than the total (what you see in the example graph) for this axis. Been looking at some online documentation but I haven’t been able to resolve this yet.

I just managed to get this working by changing the kind to “bar” and using the total as the y-axis.

Hi! I have the same issue (Almost) with the number of bars chart:

AssertionError: 25 != 13 : Expected a different number of bars chart.

(but my chart looks exactly like the one in the figure)

Did you find any solution? I tried to change the catplot to kind=bar, like
craig.lunney suggested, but I keep getting the same error… I don’t know if maybe there’s something like a merge thing we can do with the bars… I’m running out of ideas here :pensive:
Thanks!

Fixed it! what happened was when I wrote the code from my jupyter notebook, I forgot to add the code line that changes the value of ‘gluc’ to 0 or 1 :sweat_smile:, so I was having too many values for the ‘value’ col (not only 0s or 1s) that’s why the test didn’t succeed.
I hope this helps anyone :slight_smile:
Thanks!