As a learning exercise can someone see why this solution pass all tests except the number of columns test. I’ve been struggling to see why but just can’t grasp it.
The Error:
F....c:\Users\jvs00\Study\Python\fCC Data Analysis with Python\01 - Certification Projects\page-view-time-series-visualiser\test_module.py:7: FutureWarning: Calling int on a single element Series is deprecated and will raise a TypeError in the future. Use int(ser.iloc[0]) instead
actual = int(time_series_visualizer.df.count(numeric_only=True))
....
======================================================================
FAIL: test_bar_plot_number_of_bars (test_module.BarPlotTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "c:\Users\jvs00\Study\Python\fCC Data Analysis with Python\01 - Certification Projects\page-view-time-series-visualiser\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: 57 != 49 : Expected a different number of bars in bar chart.
----------------------------------------------------------------------
The Code:
# Copy and modify data for monthly bar plot
df_bar_g = df.copy(True)
df_bar_g['year'] = df_bar_g.index.year
df_bar_g['month'] = df_bar_g.index.month
print(df_bar_g)
df_bar_g = df_bar_g.groupby(['year', 'month'], as_index=False).mean()
df_bar_g['month_name'] = pd.to_datetime(df_bar_g['month'], format='%m').dt.month_name()
print(df_bar_g)
fig, ax = plt.subplots(figsize=(7, 8))
sns.barplot(
data = df_bar_g,
x = 'year',
y = 'value',
hue = 'month_name',
hue_order =
[
'January',
'February',
'March',
'April',
'May','June',
'July',
'August',
'September',
'October',
'November',
'December'
],
palette = 'Paired',
ax=ax)
ax.set_xlabel('Years')
ax.set_ylabel('Average Page Views')
ax.legend(title='Months', loc='best')
#plt.show()
#plt.close()
The output:
