Data Analysis with Python Projects - Page View Time Series Visualizer

Tell us what’s happening:

Describe your issue in detail here.
I don’t understand what is the issue, my code doesn’t even run, but to me it seems fine
→ poetry add matplotlib
Using version ^3.8.1 for matplotlib

Updating dependencies
Resolving dependencies…

The current project’s Python requirement (>=3.7,<4.0) is not compatible with some of the required packages Python requirement:

  • matplotlib requires Python >=3.9, so it will not be satisfied for Python >=3.7,<3.9

Because no versions of matplotlib match >3.8.1,<4.0.0
and matplotlib (3.8.1) requires Python >=3.9, matplotlib is forbidden.
So, because root depends on matplotlib (^3.8.1), version solving failed.

• Check your dependencies Python requirement: The Python requirement can be specified via the python or markers properties

For matplotlib, a possible solution would be to set the `python` property to ">=3.9,<4.0"

https://python-poetry.org/docs/dependency-specification/#python-restricted-dependencies,
https://python-poetry.org/docs/dependency-specification/#using-environment-markers

exit status 1
/home/runner/boilerplate-page-view-time-series-visualizer-1/time_series_visualizer.py:38: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning.
df_bar = df_bar.groupby([‘year’,‘month’]).value.mean().unstack()

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’,index_col=‘date’)
df.index=pd.to_datetime(df.index)

Clean data

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

def draw_line_plot():

# Draw line plot
fig,ax=plt.subplots(figsize=(15,5))
plt.plot(df.index,df.value,color='firebrick')
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_bar=df.copy()
df_bar[‘month’]=df_bar.index.month_name()
df_bar[‘year’]=df_bar.index.year
month_list=[“January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December”]
df_bar[‘month’]=df_bar.month.astype(‘category’).cat.set_categories(month_list,ordered=True)

df_bar = df_bar.groupby(['year','month']).value.mean().unstack()

# Draw bar plot

fig = df_bar.plot.bar(figsize=(12,6),legend=True,xlabel='Years', ylabel='Average Page Views').figure
ax=plt.gca()
ax.legend(title='Months')
plt.show()

# 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]
months_list= [‘Jan’, ‘Feb’, ‘Mar’, ‘Apr’, ‘May’, ‘Jun’, ‘Jul’, ‘Aug’, ‘Sep’, ‘Oct’, ‘Nov’, ‘Dec’]
df[‘month’]=df_box.month.astype(‘category’).cat.set_categories(months_list,ordered=True)

# Draw box plots (using Seaborn)
fig,ax=plt.subplots(1,2,figsize=(15,5))
ax[0]=sns.boxplot(x=df_box['year'],y=df_box['value'],ax=ax[0])
ax[0].set_title('Year-wise Box Plot (Trend)')
ax[0].set_xlabel('Year')
ax[0].set_ylabel('Page Views')
ax[0].set_yticks(range(0, 220000, 20000))

ax[1]=sns.boxplot(x=df_box['month'],y=df_box['value'],ax=ax[1],order=months_list)
ax[1].set_title('Month-wise Box Plot (Seasonality)')
ax[1].set_xlabel('Month')
ax[1].set_ylabel('Page Views')
ax[1].set_yticks(range(0, 220000, 20000))






# 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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36

Challenge Information:

Data Analysis with Python Projects - Page View Time Series Visualizer

In the Files menu to the side, show hidden files and then delete poetry.lock, pyproject.toml and replit.nix

Screenshot 2023-10-02 073220

I deleted the poetry.lock,pyproject.toml files…I couldn’t find replit.nix file, I deleted .replit file and now my error is like this
Run isn’t configured. Try adding a .replit and configuring it https://docs.replit.com/programming-ide/configuring-run-button
I don’t know how to configure a run button

Don’t delete your .replit file :+1:

You can put this in it:

modules = ["python-3.10:v18-20230807-322e88b"]

hidden = [".pythonlibs"]
run = "python3 main.py"

[nix]
channel = "stable-23_05"

[deployment]
run = ["sh", "-c", "Use run command"]
deploymentTarget = "cloudrun"

When I ran this in a newly created .replit file, poetry.lock and pyproject.toml files were again created which I had deleted previously and I am getting error like this
/home/runner/boilerplate-page-view-time-series-visualizer-1/time_series_visualizer.py:38: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning.
df_bar = df_bar.groupby([‘year’,‘month’]).value.mean().unstack()
^CTraceback (most recent call last):
File “/home/runner/boilerplate-page-view-time-series-visualizer-1/main.py”, line 7, in
time_series_visualizer.draw_bar_plot()
File “/home/runner/boilerplate-page-view-time-series-visualizer-1/time_series_visualizer.py”, line 45, in draw_bar_plot
plt.show()
File “/home/runner/boilerplate-page-view-time-series-visualizer-1/.pythonlibs/lib/python3.10/site-packages/matplotlib/pyplot.py”, line 527, in show
return _get_backend_mod().show(*args, **kwargs)
File “/home/runner/boilerplate-page-view-time-series-visualizer-1/.pythonlibs/lib/python3.10/site-packages/matplotlib/backend_bases.py”, line 3448, in show
cls.mainloop()
File “/home/runner/boilerplate-page-view-time-series-visualizer-1/.pythonlibs/lib/python3.10/site-packages/matplotlib/backends/_backend_tk.py”, line 523, in start_main_loop
first_manager.window.mainloop()
File “/nix/store/xf54733x4chbawkh1qvy9i1i4mlscy1c-python3-3.10.11/lib/python3.10/tkinter/init.py”, line 1458, in mainloop
self.tk.mainloop(n)
KeyboardInterrupt

Try letting it run. I only see a warning here.

Please provide a link to your replit so I can test it?

This is what I get
/home/runner/boilerplate-page-view-time-series-visualizer-1/time_series_visualizer.py:38: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning.
df_bar = df_bar.groupby([‘year’,‘month’]).value.mean().unstack()

it just keeps on running.
here is the link to my replit file boilerplate-page-view-time-series-visualizer (1) - Replit

You are maxing out your CPU/memory.

Comment out plt.show()

You can also comment out these lines in main.py:

time_series_visualizer.draw_line_plot()
time_series_visualizer.draw_bar_plot()
time_series_visualizer.draw_box_plot()

You don’t need those running every time you want to run the tests.

Thank You it works now. But, one small doubt, how did it work even after I commented out these three lines time_series_visualizer.draw_line_plot()
time_series_visualizer.draw_bar_plot()
time_series_visualizer.draw_box_plot()
I thought these lines in main.py were the ones that tested my funtion

These lines are for you to test your functions as you’re writing the code. You could replace these with whatever functions calls and arguments that you want to test, to see the output. (Usually it would be something like

print(time_series_visualizer.draw_bar_plot())

because you want to see some output, but here you are just generating images.)

# Run unit tests automatically
main(module='test_module', exit=False)

This line is running test_module.py which contains all of the fCC test data. While you’re writing your code and doing early testing you can comment out this line so it doesn’t run all of the tests every time you run it.