I am having this error and can’t find the solution. Does anyone knows how to fix it? Thanks in advance.
...F...E...
======================================================================
ERROR: test_data_cleaning (test_module.DataCleaningTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-page-view-time-series-visualizer/test_module.py", line 7, in test_data_cleaning
actual = int(time_series_visualizer.df.count(numeric_only=True))
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pandas/core/series.py", line 129, in wrapper
raise TypeError(f"cannot convert the series to {converter}")
TypeError: cannot convert the series to <class 'int'>
and
FAIL: test_box_plot_labels (test_module.BoxPlotTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-page-view-time-series-visualizer/test_module.py", line 99, in test_box_plot_labels
self.assertEqual(actual, expected, "Expected box plot 2 secondary labels to be 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'")
AssertionError: Lists differ: ['May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', [36 chars]Apr'] != ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', [36 chars]Dec']
First differing element 0:
'May'
'Jan'
+ ['Jan',
+ 'Feb',
+ 'Mar',
+ 'Apr',
- ['May',
? ^
+ 'May',
? ^
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
- 'Dec',
? ^
+ 'Dec']
? ^
- 'Jan',
- 'Feb',
- 'Mar',
- 'Apr'] : Expected box plot 2 secondary labels to be 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
CODE:
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
# Import data (Make sure to parse dates. Consider setting index column to 'date'.)
df = pd.read_csv('fcc-forum-pageviews.csv')
# Clean data
df.date = pd.to_datetime(df.date)
df = df[(df.value >= (df.value.quantile(0.025))) & (df.value <= (df.value.quantile(0.975)))]
def draw_line_plot():
plt.figure(figsize=(14,6))
plt.title('Daily freeCodeCamp Forum Page Views 5/2016-12/2019')
fig = sns.lineplot(data=df, x='date', y='value').figure
plt.xlabel("Date")
plt.ylabel("Page Views")
# Save image and return fig (don't change this part)
fig.savefig('line_plot.png')
return fig
def draw_bar_plot():
# Copy and modify data for monthly bar plot
df_bar = pd.DataFrame(df)
df_bar['Year'] = df['date'].dt.year
df_bar['Month'] = df['date'].dt.month
df_bar_ave = df_bar.groupby(['Year', 'Month']).mean().unstack()
months = ['January', 'February', 'March', 'April' , 'May' , 'June', 'July', 'August', 'September', 'October', 'November', 'December']
# Draw bar plot
fig = df_bar_ave.plot(kind ="bar", figsize=(15,5)).figure
#plt.title("Average daily page views, by Month")
plt.xlabel("Years")
plt.ylabel("Average Page Views")
plt.legend(fontsize =10, labels=months)
# Save image and return fig (don't change this part)
fig.savefig('bar_plot.png')
return fig
def draw_box_plot():
# Prepare data for box plots (this part is done!)
df_box = pd.DataFrame(df)
df_box['Year'] = df['date'].dt.year
df_box['Month'] = df['date'].dt.month
df_box.loc[df_box['Month'] == 1, 'Month'] = "Jan"
df_box.loc[df_box['Month'] == 2, 'Month'] = "Feb"
df_box.loc[df_box['Month'] == 3, 'Month'] = "Mar"
df_box.loc[df_box['Month'] == 4, 'Month'] = "Apr"
df_box.loc[df_box['Month'] == 5, 'Month'] = "May"
df_box.loc[df_box['Month'] == 6, 'Month'] = "Jun"
df_box.loc[df_box['Month'] == 7, 'Month'] = "Jul"
df_box.loc[df_box['Month'] == 8, 'Month'] = "Aug"
df_box.loc[df_box['Month'] == 9, 'Month'] = "Sep"
df_box.loc[df_box['Month'] == 10, 'Month'] = "Oct"
df_box.loc[df_box['Month'] == 11, 'Month'] = "Nov"
df_box.loc[df_box['Month'] == 12, 'Month'] = "Dec"
# Draw box plots (using Seaborn)
fig, axes = plt.subplots(figsize=(20, 5), ncols=2, sharex=False)
sns.despine(left=True)
box_plot_year = sns.boxplot(x=df_box['Year'], y=df_box.value, ax=axes[0])
box_plot_year.set_title("Year-wise Box Plot (Trend)")
box_plot_year.set_xlabel('Year')
box_plot_year.set_ylabel('Page Views')
box_plot_month = sns.boxplot(x=df_box['Month'], y=df_box.value, ax=axes[1])
box_plot_month.set_title("Month-wise Box Plot (Seasonality)")
box_plot_month.set_xlabel('Month')
box_plot_month.set_ylabel('Page Views')
# Save image and return fig (don't change this part)
fig.savefig('box_plot.png')
return fig
Thank you!