Data Analysis with Python Projects - Page View Time Series Visualizer

Tell us what’s happening:
I’ve looked through other post on this project in the forum search for “must have the same dimension”

This is the error I’m getting:

Traceback (most recent call last):
File “main.py”, line 6, in
time_series_visualizer.draw_line_plot()
Traceback (most recent call last):
File “main.py”, line 6, in
time_series_visualizer.draw_line_plot()
Traceback (most recent call last):
File “main.py”, line 6, in
time_series_visualizer.draw_line_plot()
File “/home/runner/Time-Series/time_series_visualizer.py”, line 16, in draw_line_plot
plt.plot(‘date’, ‘value’, data=df)
File “/home/runner/Time-Series/venv/lib/python3.10/site-packages/matplotlib/pyplot.py”, line 2785, in plot
return gca().plot(
File “/home/runner/Time-Series/venv/lib/python3.10/site-packages/matplotlib/axes/_axes.py”, line 1688, in plot
lines = [*self._get_lines(*args, data=data, **kwargs)]
File “/home/runner/Time-Series/venv/lib/python3.10/site-packages/matplotlib/axes/_base.py”, line 311, in call
yield from self._plot_args(
File “/home/runner/Time-Series/venv/lib/python3.10/site-packages/matplotlib/axes/_base.py”, line 504, in _plot_args
raise ValueError(f"x and y must have same first dimension, but "
ValueError: x and y must have same first dimension, but have shapes (1,) and (1238,)

Describe your issue in detail here.

Your code so far

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

Import data (Make sure to parse dates. Consider setting index column to ‘date’.)

df = pd.read_csv(“fcc-forum-pageviews.csv”)
df.sort_values(by=“date”, inplace=True)
df.set_index(‘date’, inplace=True)

Clean data

df = df[(df[‘value’] >= df[‘value’].quantile(0.025)) & (df[‘value’] <= df[‘value’].quantile(0.975))]

def draw_line_plot():
fig, ax = plt.subplots()
plt.plot(‘date’, ‘value’, data=df)
plt.title(“Daily freeCodeCamp Forum Page Views 5/2016-12/2019”)
plt.xlabel(“Date”)
plt.ylabel(“Page Views”)

# Save image and return fig (don't change this part)

fig.savefig(‘line_plot.png’)
return fig

def draw_bar_plot():
# Copy and modify data for monthly bar plot
df[‘date’]= pd.to_datetime(df[‘date’])
df_bar[‘year’] = pd.DatetimeIndex(df_bar[‘date’]).year
df_bar[‘month’] = pd.DatetimeIndex(df_bar[‘date’]).month_name()

df_bar = df.groupby([df['date'].dt.year, df['date'].dt.month]).mean()

# Draw bar plot
sns.barplot(data=df_bar, x="year", y="value", hue="month_name")
plt.xlabel("Year")
plt.ylabel("Average Page Views")
plt.legend(loc='upper left')



# Save image and return fig (don't change this part)
fig.savefig('bar_plot.png')
return fig

def draw_box_plot():
# Prepare data for box plots (this part is done!)
df_box = df.copy()
df_box.reset_index(inplace=True)
df_box[‘year’] = [d.year for d in df_box.date]
df_box[‘month’] = [d.strftime(‘%b’) for d in df_box.date]

# Draw box plots (using Seaborn)
seaborn.boxplot(data=None, *, x=None, y=None, hue=None)




# Save image and return fig (don't change this part)
fig.savefig('box_plot.png')
return fig

Your browser information:

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

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

Link to the challenge:

I’m not certain that this is the source of the error, but it doesn’t look to me like you’re actually creating a line plot.

Here’s some documentation on how to do that:
https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.plot.line.html

You’ll need to post a link to a repl or format the code in your post so that other can easily execute it since block-quoting destroys the indentation that python requires.

Without running the code, however, I believe the error is similar to another recently posted about this project. You should definitely follow the hint to Make sure to parse dates. in your call to pd.read_csv() as you are currently not doing that.

https://replit.com/@BenjaminC12/Time-Series#time_series_visualizer.py

You’ve got the dates parsed and in the data frame now, but then you index them away and your bar and box plots can’t work. Starting with your indexing, you should start printing the data frame before and after each change to insure you are making the intended change correctly and look at the documentation for each function you call involving the data frame if the results are not what you want.

There is a recent thread in the forum about the different interfaces to matplotlib that you should probably read for some pointers.