Data Analysis with Python Projects - Sea Level Predictor

Tell us what’s happening:

Hi, i cant pass test in sea level predictor even test value are same as my. I went through forum suggesting downgrade pandas to 1.1.5 but i cant downgrade python on gitpod

Your code so far

https://freecodecam-boilerplate-po6xhybrm19.ws-eu118.gitpod.io

import pandas as pd
import matplotlib.pyplot as plt
from scipy.stats import linregress

def draw_plot():
    # Read data from file
    df = pd.read_csv('epa-sea-level.csv')
    # Create scatter plot
    fig, ax = plt.subplots(figsize=(16,8))
    ax.scatter(df['Year'],df['CSIRO Adjusted Sea Level'])
    # Create first line of best fit
    slope, intercept, r_value, p_value, std_err = linregress(df['Year'], df['CSIRO Adjusted Sea Level'])
    year_extended = range(df['Year'].min(), 2051)
    ax.plot(year_extended, slope * year_extended + intercept, label='Best fit line (All data)', color='r')

    # mark fot prediction 2050
    ax.plot(2050,slope * 2050 + intercept, 'ro')
    # Create second line of best fit
    df_recent = df[df['Year'] >= 2000]
    slope_recent, intercept_recent,_, _, _ = linregress(df_recent['Year'], df_recent['CSIRO Adjusted Sea Level'])
    year_extended_recent = range(df_recent['Year'].min(), 2051)
    ax.plot(year_extended_recent, [slope_recent * year + intercept_recent for year in year_extended_recent], label = 'Best fit line (from 2000)', color='g')
    
    # Add labels and title
    ax.set_title('Rise in Sea Level')
    ax.set_xlabel('Year')
    ax.set_ylabel('Sea Level (inches)')
    
    # Save plot and return data for testing (DO NOT MODIFY)
    plt.savefig('sea_level_plot.png')
    return plt.gca()

And test module error

gitpod /workspace/boilerplate-sea-level-predictor (main) $ python main.py
..F.
======================================================================
FAIL: test_plot_lines (test_module.LinePlotTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/workspace/boilerplate-sea-level-predictor/test_module.py", line 38, in test_plot_lines
    np.testing.assert_almost_equal(actual, expected, 7, "Expected different line for second line of best fit.")
  File "/home/gitpod/.pyenv/versions/3.8.20/lib/python3.8/contextlib.py", line 75, in inner
    return func(*args, **kwds)
  File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/numpy/testing/_private/utils.py", line 588, in assert_almost_equal
    return assert_array_almost_equal(actual, desired, decimal, err_msg)
  File "/home/gitpod/.pyenv/versions/3.8.20/lib/python3.8/contextlib.py", line 75, in inner
    return func(*args, **kwds)
  File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/numpy/testing/_private/utils.py", line 1099, in assert_array_almost_equal
    assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose,
  File "/home/gitpod/.pyenv/versions/3.8.20/lib/python3.8/contextlib.py", line 75, in inner
    return func(*args, **kwds)
  File "/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/numpy/testing/_private/utils.py", line 778, in assert_array_compare
    raise AssertionError(msg)
AssertionError: 
Arrays are not almost equal to 7 decimals
Expected different line for second line of best fit.
(shapes (1,), (51,) mismatch)
 x: array([10.1754553])
 y: array([ 7.0610799,  7.2275071,  7.3939344,  7.5603617,  7.726789 ,
        7.8932162,  8.0596435,  8.2260708,  8.392498 ,  8.5589253,
        8.7253526,  8.8917799,  9.0582071,  9.2246344,  9.3910617,...

----------------------------------------------------------------------
Ran 4 tests in 0.765s

FAILED (failures=1)

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36

Challenge Information:

Data Analysis with Python Projects - Sea Level Predictor