Data Analysis with Python Projects - Sea Level Predictor

Tell us what’s happening:

am current work on time series visualize . i got the error message below, am not sure how to fix the problem cause am 100% i did include any floats in my project.
File “/workspace/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.8/site-packages/seaborn/categorical.py”, line 339, in is_not_numeric
np.asarray(s, dtype=np.float)
File “/workspace/boilerplate-page-view-time-series-visualizer/.venv/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

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/124.0.0.0 Safari/537.36

Challenge Information:

Data Analysis with Python Projects - Sea Level Predictor

1 Like

What version of numpy is installed?

You can try installing this verion:

pip install --force-reinstall numpy==1.20.3

https://forum.freecodecamp.org/t/data-analysis-with-python-projects-medical-data-visualizer/673292/2

https://forum.freecodecamp.org/t/data-analysis-with-python-projects/683279/2

thank you[quote=“pkdvalis, post:2, topic:687311, full:true”]
What version of numpy is installed?

You can try installing this verion:

pip install --force-reinstall numpy==1.20.3

[/quote]
let me try and i will get back to you.

i tried it and it failed. i also tried pip install numpy==1.19.5 ,
install numpy==1.20 would crech cause it was missing
pip install --upgrade pip setuptools,
pip cache purge
conda install numpy
python -m venv myenv
source myenv/bin/activate

Can you share the command you ran and the exact error please?

@MMabathoN ➜ /workspaces/boilerplate-page-view-time-series-visualizer (main) $ /workspaces/boilerplate-page-view-time-series-visualizer/.venv/bin/python /workspaces/boilerplate-page-view-time-series-visualizer/test_module.py
EEEEEEE....
======================================================================
ERROR: test_bar_plot_labels (__main__.BarPlotTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/workspaces/boilerplate-page-view-time-series-visualizer/test_module.py", line 37, in setUp
    self.fig = time_series_visualizer.draw_bar_plot()
  File "/workspaces/boilerplate-page-view-time-series-visualizer/time_series_visualizer.py", line 39, in draw_bar_plot
    df_bar.columns = ['January', 'February', 'March', 'April', 'May' 'June', 'July', 'August', 'September', 'October', 'November', 'December']
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/pandas/core/generic.py", line 5915, in __setattr__
    return object.__setattr__(self, name, value)
  File "pandas/_libs/properties.pyx", line 69, in pandas._libs.properties.AxisProperty.__set__
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/pandas/core/generic.py", line 823, in _set_axis
    self._mgr.set_axis(axis, labels)
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/pandas/core/internals/managers.py", line 230, in set_axis
    self._validate_set_axis(axis, new_labels)
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/pandas/core/internals/base.py", line 70, in _validate_set_axis
    raise ValueError(
ValueError: Length mismatch: Expected axis has 12 elements, new values have 11 elements

======================================================================
ERROR: test_bar_plot_legend_labels (__main__.BarPlotTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/workspaces/boilerplate-page-view-time-series-visualizer/test_module.py", line 37, in setUp
    self.fig = time_series_visualizer.draw_bar_plot()
  File "/workspaces/boilerplate-page-view-time-series-visualizer/time_series_visualizer.py", line 39, in draw_bar_plot
    df_bar.columns = ['January', 'February', 'March', 'April', 'May' 'June', 'July', 'August', 'September', 'October', 'November', 'December']
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/pandas/core/generic.py", line 5915, in __setattr__
    return object.__setattr__(self, name, value)
  File "pandas/_libs/properties.pyx", line 69, in pandas._libs.properties.AxisProperty.__set__
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/pandas/core/generic.py", line 823, in _set_axis
    self._mgr.set_axis(axis, labels)
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/pandas/core/internals/managers.py", line 230, in set_axis
    self._validate_set_axis(axis, new_labels)
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/pandas/core/internals/base.py", line 70, in _validate_set_axis
    raise ValueError(
ValueError: Length mismatch: Expected axis has 12 elements, new values have 11 elements

======================================================================
ERROR: test_bar_plot_number_of_bars (__main__.BarPlotTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/workspaces/boilerplate-page-view-time-series-visualizer/test_module.py", line 37, in setUp
    self.fig = time_series_visualizer.draw_bar_plot()
  File "/workspaces/boilerplate-page-view-time-series-visualizer/time_series_visualizer.py", line 39, in draw_bar_plot
    df_bar.columns = ['January', 'February', 'March', 'April', 'May' 'June', 'July', 'August', 'September', 'October', 'November', 'December']
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/pandas/core/generic.py", line 5915, in __setattr__
    return object.__setattr__(self, name, value)
  File "pandas/_libs/properties.pyx", line 69, in pandas._libs.properties.AxisProperty.__set__
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/pandas/core/generic.py", line 823, in _set_axis
    self._mgr.set_axis(axis, labels)
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/pandas/core/internals/managers.py", line 230, in set_axis
    self._validate_set_axis(axis, new_labels)
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/pandas/core/internals/base.py", line 70, in _validate_set_axis
    raise ValueError(
ValueError: Length mismatch: Expected axis has 12 elements, new values have 11 elements

======================================================================
ERROR: test_box_plot_labels (__main__.BoxPlotTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/workspaces/boilerplate-page-view-time-series-visualizer/test_module.py", line 68, in setUp
    self.fig = time_series_visualizer.draw_box_plot()
  File "/workspaces/boilerplate-page-view-time-series-visualizer/time_series_visualizer.py", line 65, in draw_box_plot
    sns.boxplot(x='year', y='value', data=df_box, ax=axes[0])
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/seaborn/categorical.py", line 2229, in boxplot
    plotter = _BoxPlotter(x, y, hue, data, order, hue_order,
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/seaborn/categorical.py", line 446, in __init__
    self.establish_variables(x, y, hue, data, orient, order, hue_order)
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/seaborn/categorical.py", line 158, in establish_variables
    orient = self.infer_orient(x, y, orient)
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/seaborn/categorical.py", line 359, in infer_orient
    elif is_not_numeric(y):
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/seaborn/categorical.py", line 339, in is_not_numeric
    np.asarray(s, dtype=np.float)
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/numpy/__init__.py", line 324, 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:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

======================================================================
ERROR: test_box_plot_number (__main__.BoxPlotTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/workspaces/boilerplate-page-view-time-series-visualizer/test_module.py", line 68, in setUp
    self.fig = time_series_visualizer.draw_box_plot()
  File "/workspaces/boilerplate-page-view-time-series-visualizer/time_series_visualizer.py", line 65, in draw_box_plot
    sns.boxplot(x='year', y='value', data=df_box, ax=axes[0])
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/seaborn/categorical.py", line 2229, in boxplot
    plotter = _BoxPlotter(x, y, hue, data, order, hue_order,
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/seaborn/categorical.py", line 446, in __init__
    self.establish_variables(x, y, hue, data, orient, order, hue_order)
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/seaborn/categorical.py", line 158, in establish_variables
    orient = self.infer_orient(x, y, orient)
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/seaborn/categorical.py", line 359, in infer_orient
    elif is_not_numeric(y):
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/seaborn/categorical.py", line 339, in is_not_numeric
    np.asarray(s, dtype=np.float)
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/numpy/__init__.py", line 324, 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:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

======================================================================
ERROR: test_box_plot_number_of_boxes (__main__.BoxPlotTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/workspaces/boilerplate-page-view-time-series-visualizer/test_module.py", line 68, in setUp
    self.fig = time_series_visualizer.draw_box_plot()
  File "/workspaces/boilerplate-page-view-time-series-visualizer/time_series_visualizer.py", line 65, in draw_box_plot
    sns.boxplot(x='year', y='value', data=df_box, ax=axes[0])
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/seaborn/categorical.py", line 2229, in boxplot
    plotter = _BoxPlotter(x, y, hue, data, order, hue_order,
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/seaborn/categorical.py", line 446, in __init__
    self.establish_variables(x, y, hue, data, orient, order, hue_order)
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/seaborn/categorical.py", line 158, in establish_variables
    orient = self.infer_orient(x, y, orient)
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/seaborn/categorical.py", line 359, in infer_orient
    elif is_not_numeric(y):
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/seaborn/categorical.py", line 339, in is_not_numeric
    np.asarray(s, dtype=np.float)
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/numpy/__init__.py", line 324, 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:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

======================================================================
ERROR: test_box_plot_titles (__main__.BoxPlotTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/workspaces/boilerplate-page-view-time-series-visualizer/test_module.py", line 68, in setUp
    self.fig = time_series_visualizer.draw_box_plot()
  File "/workspaces/boilerplate-page-view-time-series-visualizer/time_series_visualizer.py", line 65, in draw_box_plot
    sns.boxplot(x='year', y='value', data=df_box, ax=axes[0])
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/seaborn/categorical.py", line 2229, in boxplot
    plotter = _BoxPlotter(x, y, hue, data, order, hue_order,
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/seaborn/categorical.py", line 446, in __init__
    self.establish_variables(x, y, hue, data, orient, order, hue_order)
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/seaborn/categorical.py", line 158, in establish_variables
    orient = self.infer_orient(x, y, orient)
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/seaborn/categorical.py", line 359, in infer_orient
    elif is_not_numeric(y):
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/seaborn/categorical.py", line 339, in is_not_numeric
    np.asarray(s, dtype=np.float)
  File "/workspaces/boilerplate-page-view-time-series-visualizer/.venv/lib/python3.10/site-packages/numpy/__init__.py", line 324, 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:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

Don’t worry, i decide to rework everything .
here is a copy of my code at this moment.

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", parse_dates=['date'], index_col='date')

# 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=(16, 6))
    ax.plot(df.index, df['value'], color='r')
    ax.set_title('Daily freeCodeCamp Forum Page Views 5/2016-12/2019')
    ax.set_xlabel('Date')
    ax.set_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['year'] = df_bar.index.year
    df_bar['month'] = df_bar.index.month
    df_bar = df_bar.groupby(['year', 'month'])['value'].mean().unstack()
    df_bar.columns = ['January', 'February', 'March', 'April', 'May' 'June', 'July', 'August', 'September', 'October', 'November', 'December']

    # Draw bar plot
    fig, ax = plt.subplots(figsize=(10, 6))
    ax = df_bar.plot(kind='bar', ax=ax)
    ax.set_xlabel('Years')
    ax.set_ylabel('Average Page Views')
    ax.legend(title='Months')
    fig.tight_layout()




    # 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)
    fig, axes = plt.subplots(1, 2, figsize=(16, 6))
    sns.boxplot(x='year', y='value', data=df_box, ax=axes[0])
    axes[0].set_title('Year-wise Box Plot (Trend)')
    axes[0].set_xlabel('Year')
    axes[0].set_ylabel('Page Views')
    sns.boxplot(x='month', y='value', data=df_box, ax=axes[1])
    axes[1].set_title('Month-wise Box Plot (Seasonality)')
    axes[1].set_xlabel('Month')
    
                 




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

i think the reason why am encountering this problem is cause of how i cleaned the data … if i process each item independently. the issue will be automatically resolved .

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

i used pip install numpy==1.23.5 instead

The goal is to downgrade numpy to a version that will work with the tests.

Try this version:

pip install --force-reinstall numpy==1.20.3

It has worked in the other threads that I linked.

So, you’re working on Page View Time Series and not the Sea Level Predictor?

i was working on both semiseriously cause at some point i was stuck and frustrated so so i decided to shift my focus .
at times i am supper lazy so when do decided to work on something i wont stop until am done.

Ok, but when you open a thread you really need to pick a project and a specific problem / question or error to work on. It’s too confusing this way.

I’ll close this for now, please open a new thread when you decide what you want to work on, thanks!