Tell us what’s happening:
The image shows the error message I get after running my code on replit.
Below is my codes so far for the project:
import pandas as pd
import matplotlib.pyplot as plt
from scipy.stats import linregress
def draw_plot():
# Read data from file
df = pd.csv(“epa-sea-level.csv”)
y = df[“CSIRO Adjusted Sea Level”]
x = df[“Year”]
# Create scatter plot
fig, ax = plt.subplots()
plt.scatter(x, y)
# Create first line of best fit
res = linregress(x, y)
print(res)
x_pred = pd.Series([i for i in range(1880, 2051)])
y_pred = res.slope*x_pred + res.intercept
plt.plot(x_pred, y_pred, "r")
# Create second line of best fit
new_def = df.loc[df['Year'] >= 2000]
new_x = new_df['Year']
new_y = new_df["CSIRO Adjusted Sea Level"]
res_2 = linregress(new_x, new_y)
x_pred2 = pd.Series([i for i in range(2000, 2050)])
y_pred2 = res_2.slope*x_pred2 + res_2.intercept
plt.plot(x_pred2, y_pred2, 'green')
# Add labels and title
ax.set_xlabel('Year')
ax.set_ylabel('Sea Level (inches)')
ax.set_title('Rise in Sea Level')
# Save plot and return data for testing (DO NOT MODIFY)
plt.savefig('sea_level_plot.png')
return plt.gca()
Your code so far
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/112.0
Challenge: Data Analysis with Python Projects - Sea Level Predictor
Link to the challenge: