Page views Time Series Visualizer - failed

My code’s output are the same with given example but do not pass the test. Anyone here know why?

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'.)
csv_url = 'fcc-forum-pageviews.csv'
df = pd.read_csv(
    csv_url, 
    parse_dates=['date'],
    index_col='date'
    )

# Clean data
df = df = df[
   (df.value >= df.value.quantile(0.025))
   & (df.value <= df.value.quantile(0.975))]


def draw_line_plot():
    # Draw line plot
    fig, ax = plt.subplots(figsize=(20,10))
    df.plot.line(
        color='red', 
        xlabel='Date', 
        ylabel='Page Views', 
        legend=False,
        title='Daily freeCodeCamp Forum Page Views 5/2016-12/2019')


    # 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
    fig, ax = plt.subplots(figsize=(20,10))
    df_bar = df.copy()
    df_bar.reset_index(inplace=True)
    df_bar['year'] = df_bar.date.dt.year
    df_bar['month'] = df_bar.date.dt.month_name()
    df_bar = df_bar.groupby(by=['year','month'], as_index=False).mean()
    df_bar = df_bar.pivot_table(values='value', index=['year'], columns='month')

    # Draw bar plot
    df_bar.plot.bar(xlabel='Years', ylabel='Average Page Views')
    plt.legend(['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], title = '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 = df.copy()
    df_box.reset_index(inplace=True)
    df_box['year'] = [d.year for d in df_box.date]
    df_box['month'] = [d.strftime('%b') for d in df_box.date]

    # Draw box plots (using Seaborn)
    fig, axs = plt.subplots(ncols=2, figsize=(20,10))
    sns.boxplot(
        x=df_box['year'], 
        y=df_box['value'], 
        ax=axs[0]
        ).set(
            xlabel='Year', 
            ylabel='Page Views',
            title='Year-wise Box Plot (Trend)'
          )
    sns.boxplot(
        x=df_box['month'], 
        y=df_box['value'], 
        ax=axs[1],
        order=['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct','Nov', 'Dec']
        ).set(
            xlabel='Month', 
            ylabel='Page Views',
            title='Month-wise Box Plot (Seasonality)'        
        )

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

hey phuqle,

please share the link to the coding challenge with us.

best
Dennis

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.