Data Analysis with Python Projects - Page View Time Series Visualizer

Tell us what’s happening:
Whenever I try to order Months in chronological order for the barplot (order=[‘Jan’,‘Feb’,‘Mar’,‘Apr’,‘May’,‘Jun’,‘Jul’,‘Aug’,‘Sep’,‘Oct’,‘Nov’,‘Dec’]), it stops displaying bars and the legend still isn’t in the correct order. I tried solving this with sorting data beforehand but I couldn’t find a solution.


What’s weird is that it works pretty well for the following boxplot.

Your code so far

def draw_bar_plot():
    # Copy and modify data for monthly bar plot
    df_bar = df.copy()
    df_bar.reset_index(inplace=True)
    df_bar['Years'] = [d.year for d in df_bar.date]
    df_bar['Months'] = [d.strftime('%b') for d in df_bar.date]
    df_bar = df_bar.drop('date', axis=1)

    # Draw bar plot
    fig = plt.figure(figsize=(15,13))
    ax = sns.barplot(data=df_bar, x='Years', y='value', palette=sns.color_palette('tab10',12), hue='Months', errorbar=('ci', 0))
    ax.set_xlabel('Years')
    ax.set_ylabel('Average Page Views')
    #plt.show()
    # Save image and return fig (don't change this part)
    fig.savefig('bar_plot.png')
    return fig

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0

Challenge: Data Analysis with Python Projects - Page View Time Series Visualizer

Link to the challenge:

Look at the ‘Months’ column, see what it looks like. You’ll see why "(order=[‘Jan’,‘Feb’,‘Mar’,‘Apr’,… " doesn’t work.

Also, look at the overall dataframe. Can you see 1 value for each year/month pair? You need to manipulate the dataframe to achieve this.

There’s an extra video linked in the description of the project, you need to watch it because I don’t think this part was covered in the course to this point. Specifically Lecture 4 Grouping and Aggregation:
https://youtu.be/GPVsHOlRBBI?t=18108

So, I watched the video and other ressources on grouping and aggregation and resampling and I played with different ways to organize the data by month and year but I kind of always end up with multi indexing and I can’t find a way to plot the x with multiple level indices.

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