# Page View Time Series Visualizer -Bar Chart

**URL:** <https://forum.freecodecamp.org/t/page-view-time-series-visualizer-bar-chart/452072>\
**Category:** Curriculum Help\
**Tags:** python\
**Created:** [March 20, 2021, 2:22pm UTC](https://forum.freecodecamp.org/t/page-view-time-series-visualizer-bar-chart/452072 "2021-03-20T14:22:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lydia.may](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lydia.may/32/183198_2.png) [@Lydia.may](https://forum.freecodecamp.org/u/Lydia.may)\
**Post date:** [March 20, 2021, 2:22pm UTC](https://forum.freecodecamp.org/t/page-view-time-series-visualizer-bar-chart/452072/1 "2021-03-20T14:22:08Z")

</div>

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:**

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/data-analysis-with-python/data-analysis-with-python-projects/page-view-time-series-visualizer)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![CarolinaValcarce](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/carolinavalcarce/32/210436_2.png) [@CarolinaValcarce](https://forum.freecodecamp.org/u/CarolinaValcarce)\
**Post date:** [March 21, 2021, 12:52pm UTC](https://forum.freecodecamp.org/t/page-view-time-series-visualizer-bar-chart/452072/2 "2021-03-21T12:52:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [September 20, 2021, 12:52am UTC](https://forum.freecodecamp.org/t/page-view-time-series-visualizer-bar-chart/452072/3 "2021-09-20T00:52:23Z")

</div>

Closed on September 20, 2021, 12:52am UTC

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