Data Analysis with Python Projects - Sea Level Predictor

Tell us what’s happening:

I cant send my project link, please advise what to do

Your code so far

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

df = pd.read_csv(“/content/sample_data/epa-sea-level.csv”)

def draw_plot():

Create scatter plot

plt.figure(figsize=(12, 6))
plt.scatter(df['Year'], df['CSIRO Adjusted Sea Level'], label='Original Data')

# First line of best fit (all data)
slope1, intercept1, r_value1, p_value1, std_err1 = linregress(df['Year'], df['CSIRO Adjusted Sea Level'])
x_pred1 = pd.Series(range(1880, 2051))
y_pred1 = intercept1 + slope1 * x_pred1
plt.plot(x_pred1, y_pred1, 'r', label='Best Fit Line (1880-2050)')

# Second line of best fit (from year 2000)
df_recent = df[df['Year'] >= 2000]
slope2, intercept2, r_value2, p_value2, std_err2 = linregress(df_recent['Year'], df_recent['CSIRO Adjusted Sea Level'])
x_pred2 = pd.Series(range(2000, 2051))
y_pred2 = intercept2 + slope2 * x_pred2
plt.plot(x_pred2, y_pred2, 'g', label='Best Fit Line (2000-2050)')

# Plot styling
plt.xlabel('Year')
plt.ylabel('Sea Level (inches)')
plt.title('Rise in Sea Level')
plt.legend()

Save and return figure

plt.savefig('sea_level_plot.png')
return plt.gcf()

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:141.0) Gecko/20100101 Firefox/141.0

Challenge Information:

Data Analysis with Python Projects - Sea Level Predictor

You’re finished and submitting your code? You can upload your code to a github repository and submit a link to that

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