Tell us what’s happening:
Page View Time Series Visualizer
Error - ‘DataFrame’ object has no attribute ‘plt’ link of code Page-View-Time-Series-Visualizer/time_series_visualizer.py at main · Mudit5coder/Page-View-Time-Series-Visualizer · GitHub
Your code so far
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Challenge Information:
Data Analysis with Python Projects - Page View Time Series Visualizer
Can you paste the full error text please?
gitpod /workspace/boilerplate-page-view-time-series-visualizer (main) $ cd /workspace/boilerplate-page-view-time-series-visualizer ; /usr/bin/env /home/gitpod/.pyenv/shims/python /home/gitpod/.vscode-server/extensions/ms-python.debugpy-2024.8.0-linux-x64/bundled/libs/debugpy/adapter/…/…/debugpy/launcher 42963 – /workspace/boilerplate-page-view-time-series-visualizer/main.py
Traceback (most recent call last):
File “/workspace/boilerplate-page-view-time-series-visualizer/main.py”, line 6, in
time_series_visualizer.draw_line_plot()
File “/workspace/boilerplate-page-view-time-series-visualizer/time_series_visualizer.py”, line 20, in draw_line_plot
df.plt(figsize=(12, 6))
File “/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/pandas/core/generic.py”, line 5902, in getattr
return object.getattribute(self, name)
AttributeError: ‘DataFrame’ object has no attribute ‘plt’
You cannot do this:
df.plt(figsize=(12, 6))
Pandas does have a plot
function. However you are trying to use matplotlib which you’ve defined as it’s own alias here:
import matplotlib.pyplot as plt
And is accessed directly in the same way here:
plt.xlabel('Date')
You can read how to use it here:
https://matplotlib.org/stable/api/pyplot_summary.html
https://www.geeksforgeeks.org/how-to-plot-a-pandas-dataframe-with-matplotlib/
gitpod /workspace/boilerplate-page-view-time-series-visualizer (main) $ cd /workspace/boilerplate-page-view-time-series-visualizer ; /usr/bin/env /home/gitpod/.pyenv/shims/python /home/gitpod/.vscode-server/extensions/ms-python.debugpy-2024.8.0-linux-x64/bundled/libs/debugpy/adapter/…/…/debugpy/launcher 41639 – /workspace/boilerplate-page-view-time-series-visualizer/main.py
Traceback (most recent call last):
File “/workspace/boilerplate-page-view-time-series-visualizer/main.py”, line 8, in
time_series_visualizer.draw_box_plot()
File “/workspace/boilerplate-page-view-time-series-visualizer/time_series_visualizer.py”, line 70, in draw_box_plot
sns.boxplot(x=‘year’, y=‘value’, data=df, ax=axes[0])
File “/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/seaborn/categorical.py”, line 2229, in boxplot
plotter = _BoxPlotter(x, y, hue, data, order, hue_order,
File “/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/seaborn/categorical.py”, line 446, in init
self.establish_variables(x, y, hue, data, orient, order, hue_order)
File “/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/seaborn/categorical.py”, line 158, in establish_variables
orient = self.infer_orient(x, y, orient)
File “/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/seaborn/categorical.py”, line 359, in infer_orient
elif is_not_numeric(y):
File “/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/seaborn/categorical.py”, line 339, in is_not_numeric
np.asarray(s, dtype=np.float)
File “/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/numpy/init.py”, line 305, in getattr
raise AttributeError(former_attrs[attr])
AttributeError: module ‘numpy’ has no attribute ‘float’.
np.float
was a deprecated alias for the builtin float
. To avoid this error in existing code, use float
by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.float64
here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
NumPy 1.20.0 Release Notes — NumPy v2.1.dev0 Manual can you pls help me resolve this error
link - Page-View-Time-Series-Visualizer/time_series_visualizer.py at main · Mudit5coder/Page-View-Time-Series-Visualizer · GitHub
Try to read the errors to search for clues on how to fix them:
Downgrade to numpy 1.20
Some of these tests were written in previous versions and don’t work well with new versions.