Data Analysis with Python Projects - Page View Time Series Visualizer - Empty Barplot

Tell us what’s happening:
I am trying to visualize the data as a barplot in the second question, but it keeps coming out as an empty barplot, I have tried to use a dark grid but the data does not show up even though the code runs without error.

Your code so far
def draw_bar_plot():
#Copy and modify data for monthly bar plot
df_bar = df
df_bar[[‘date’, ‘month’, ‘day’]] = df_bar[‘date’].str.split(‘-’, expand=True)
df_two = df_bar.rename({‘date’:‘year’}, axis=1)
df_three = df_two.groupby([‘year’, ‘month’])[‘value’].mean().reset_index()
df_three.columns = [‘year’, ‘month’, ‘mean’]
labels = [‘January’, ‘February’, ‘March’, ‘April’, ‘May’, ‘June’, ‘July’, ‘August’, ‘September’, ‘October’, ‘November’, ‘December’]

#Draw bar plot
fig, ax = plt.subplots()
sns.catplot(data=df_three, x=‘year’,y=‘mean’, hue=‘month’)
plt.legend(loc=‘upper left’, title=‘Months’)

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36

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

Link to the challenge:

Can you link to your replit or use backticks or blockquote to paste your code? It’s all mangled.

  1. The instructions do not say to use Seaborn here (they say to use Seaborn on the next one, the box plot)

  2. Try using fig = df_three.plot.bar() instead of fig, ax = plt.subplots()

Hi, I am using matplotlib and getting a graph, but am unable to make the bars different colors based on month if I do not use seaborn, and seaborn results in the same errors I experience in the initial post. Any help would be appreciated. Code is linked below

This problem is difficult and not super clear from the material in the course. I’ve completed it though and that’s my advice:

  1. Don’t use seaborn here
  2. Use fig = df_three.plot.bar() instead of fig, ax = plt.subplots()
  3. The format of your df_three won’t work. It looks like this:
    year month           mean
0   2016    05   19432.400000
1   2016    06   21875.105263
2   2016    07   24109.678571
3   2016    08   31049.193548
4   2016    09   41476.866667
5   2016    10   27398.322581

but it needs to look like this:

month 	1 	2 	3 	4 	5 	6 	7 	8 	9 	10 	11 	12
year 												
2016 	NaN 	NaN 	NaN 	NaN 	19432.4 	21875.1 	24109.7 	31049.2 	41476.9 	27398.3 	40448.6 	27832.4
2017 	32785.2 	31113.1 	29369.1 	30878.7 	34244.3 	43577.5 	65806.8 	47712.5 	47376.8 	47438.7 	57701.6 	48420.6
2018 	58580.1 	65679.0 	62693.8 	62350.8 	56562.9 	70117.0 	63591.1 	62831.6 	65941.7 	111378.1 	78688.3 	80047.5

You can review this video at 5h02m where it shows how to do this using groupby: https://youtu.be/GPVsHOlRBBI?t=18109

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