Boxplot error for Page View Time Series Analyzer

I’m working on the Data Analysis with Python project.

When I try to create a boxplot using seaborn,

# Prepare data for box plots (this block of code is given)
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]

#Create Box Plot
fig, ax = plt.subplots(figsize=(10,10))
box_plot = sns.boxplot(data= df_box, x = "year", y = "value")

I would get a numpy attribute error:

Traceback (most recent call last):
File “main.py”, line 66, in
box_plot = sns.boxplot(data= df_box, x = “year”, y = “value”)
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

Is there a way to remedy this? I’m using Gitpod as my IDE.
Any leads would be appreciated.
Thank you so much.

I would update seaborn. This seems to have been fixed long ago.

https://github.com/mwaskom/seaborn/pull/2236

Or downgrade numpy if you can’t update seaborn.

Not sure why the boilerplate is using seaborn 0.9.0 but it looks to be incompatible with numpy 1.20 and above.

thank you so much! yes, i checked the boilerplate for another project (medical data vizualizer) and it uses seaborn 0.13.2.

so for my code, I updated seaborn using

pip install seaborn --upgrade

in my gitpod workspace. And it solved the issue. Thanks so much!

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