Page View Time Series Visualizer test_bar_plot_number_of_bars

Tell us what’s happening:
Im failing only this test: test_bar_plot_number_of_bars

Here is the error code:

======================================================================
FAIL: test_bar_plot_number_of_bars (test_module.BarPlotTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-page-view-time-series-visualizer/test_module.py", line 63, in test_bar_plot_number_of_bars
    self.assertEqual(actual, expected, "Expected a different number of bars in bar chart.")
AssertionError: 97 != 49 : Expected a different number of bars in bar chart.

----------------------------------------------------------------------
Ran 11 tests in 12.009s

FAILED (failures=1)

Your code so far

    df_bar = df_clean
    df_bar = df_bar.reset_index()
    df_bar["year"] = df_bar["date"].dt.year
    df_bar["month"] = df_bar["date"].dt.month

    df_bar_avg = df_bar.groupby(['year', 'month']).mean()
    df_bar_avg = df_bar_avg.unstack()

    months = ['January', 'February', 'March', 'April' , 'May' , 'June', 'July', 'August', 'September', 'October', 'November', 'December']

    fig = df_bar_avg.plot(kind ="bar", figsize=(15,5)).figure
    plt.xlabel("Years")
    plt.ylabel("Average Page Views")
    plt.legend(labels=months)



    # Save image and return fig (don't change this part)
    fig.savefig('bar_plot.png')
    return fig

Challenge: Page View Time Series Visualizer

Link to the challenge:

Oh I figured it out. My unstacked df_bar_avg dataframe had index as a column as well and the plot was charting out the mean() of the index numbers. I had to just drop that column and it worked!

2 Likes