Page View Time Series Visualizer -Bar Chart

Hello, does anyone know why my bar plot isn’t working? I haven’t added any code for the labels etc yet because I can’t even get a graph so I’m trying to find out what foundation isn’t working. Thank you!

Your code so far

def draw_bar_plot():
# Copy and modify data for monthly bar plot
df_bar = df.copy().reset_index
df_bar[‘year’] = df_bar[‘date’].dt.year
df_bar[‘month’] = df_bar[‘date’].dt.month
df_bar_grp = df_bar.groupby([‘year’, ‘month’])[‘value’].mean().reset_index()

# Draw bar plot

fig, ax = plt.subplots(1, figsize=(20,10))
sns.barplot(data=df_bar_grp, x='year', y='value', hue='month')



# 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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36.

Challenge: Page View Time Series Visualizer

Link to the challenge:

Hi Lydia,
I have checked your code in my IDLE. The error is in line : df_bar_grp = df_bar.groupby([‘year’, ‘month’])[‘value’].mean().reset_index().

You can try to groupby : df_bar.groupby (df_bar[“year”]).mean() or just groupby(df_bar[“month”]).mean(). But not both of them.
Anyway, if you groupby year, you get the main() of value, but also de mean() of months. You can check them by printing before ploting.
So, I think the most similar to your code to edite the graph in this way, is:

#def draw_bar_plot():
# Copy and modify data for monthly bar plot

df_bar=df.copy()
df_bar.reset_index(inplace=True)
df_bar[‘year’]= df_bar[‘date’].dt.year
df_bar[‘Months’]= df_bar[‘date’].dt.month
df_bar.set_index(‘date’, inplace=True)
df_bar=df_bar.resample(‘M’).mean()

print(df_bar)

Draw bar plot

fig, ax = plt.subplots(1, figsize=(20,10))
sns.barplot(data=df_bar, x=‘year’, y=‘value’, hue=‘Months’)

This one shows you the graphic that you were trying, even if is so different to the requested.