Page view Time Series - Months in plot

Hi everyone,

I’m doing pretty OK, I think, in getting the ‘draw_bar_plot’ right for the Page_View_Time_Series. But I see that the order of the months for 2017, 2018 and 2019 is incorrect. It has probably to do with the fact that 2016 starts with May. Anyone that can give me a clue in this one? Her is my code so far:

import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
from pandas.plotting import register_matplotlib_converters

# Import data (Make sure to parse dates. Consider setting index column to 'date'.)
df = pd.read_csv("/Users/jimsmithuis/Desktop/fcc-forum-pageviews.csv")
df.index = df['date']
df.drop(['date'], axis=1, inplace=True)

# print(f"The mean value is: {df['value'].mean().round()}")
# print(f"The lower quantile is: {df['value'].quantile(0.025)}")
# print(f"The upper quantile is: {df['value'].quantile(0.975).round()}")

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

# make additional year column
list = []
for i in df['date']:
x = pd.Series(list)
df['year'] = x

# make additional month column
list2 = []
list3 = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
for i in df['date']:
    if i[5] == '0':
        x = list3[(int(i[6])-1)]
        y = list3[(int(i[6])+9)]
x = pd.Series(list2)
df['month'] = x

# groupby
df_grouped = df.groupby(['year','month'], as_index=False, sort=False).mean()

plt.ylabel('Average Page Views')
sns.barplot(df_grouped, x='year', y='value', hue='month')

Thanks in advance!

I believe barplot has some ordering options for different things :slight_smile:

1 Like

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