<jupyter_start><jupyter_text>Use Pandas to import the data from `epa-sea-level.csv`<jupyter_code>import pandas as pd
import matplotlib.pyplot as plt
from scipy.stats import linregress
df_1880_to_2013 = pd.read_csv('epa-sea-level.csv',float_precision="legacy")
df_1880_to_2013<jupyter_output><empty_output><jupyter_text>Use matplotlib to create a scatter plot using the "Year" column as the x-axis and the "CSIRO Adjusted Sea Level" column as the y-axis.<jupyter_code>fig ,ax = plt.subplots(figsize = (15,5))
x = df_1880_to_2013['Year']
y = df_1880_to_2013['CSIRO Adjusted Sea Level']
ax.scatter(x,y)
ax.set(xlabel = "Years", ylabel = "CSIRO Adjusted Sea Level")<jupyter_output><empty_output><jupyter_text>Use the `linregress` function from `scipy.stats` to get the slope and y-intercept of the line of best fit.Plot the line of best fit over the top of the scatter plot. Make the line go through the year 2013 to predict the sea level rise in 2013.<jupyter_code>result = linregress(df_1880_to_2013['Year'], df_1880_to_2013['CSIRO Adjusted Sea Level'])
result
fig ,ax = plt.subplots(figsize = (15,5))
x = df_1880_to_2013['Year']
y = df_1880_to_2013['CSIRO Adjusted Sea Level']
ax.scatter(x,y)
ax.set(xlabel = "Years", ylabel = "CSIRO Adjusted Sea Level")
ax.plot(df_1880_to_2013['Year'],result.slope*df_1880_to_2013['Year']+ result.intercept,'r')<jupyter_output><empty_output><jupyter_text>Plot a new line of best fit just using the data from year 2000 through the most recent year in the dataset. Make the line also go through the year 2013 to predict the sea level rise in 2013 if the rate of rise continues as it has since the year 2000. The x label should be "Year", the y label should be "Sea Level (inches)", and the title should be "Rise in Sea Level"<jupyter_code>df_2000_to_2013 = df_1880_to_2013[df_1880_to_2013['Year'] >= 2000]
df_2000_to_2013
result_1 = linregress(df_2000_to_2013['Year'], df_2000_to_2013['CSIRO Adjusted Sea Level'])
result_1
fig ,ax = plt.subplots(figsize = (15,5))
x = df_1880_to_2013['Year']
y = df_1880_to_2013['CSIRO Adjusted Sea Level']
ax.scatter(x,y)
ax.set(xlabel = "Year", ylabel = "Sea Level (inches)", title ="Rise in Sea Level")
ax.plot(df_1880_to_2013['Year'],result.slope*df_1880_to_2013['Year']+ result.intercept,'g')
ax.plot(df_2000_to_2013['Year'],result_1.slope*df_2000_to_2013['Year']+ result_1.intercept,'red')<jupyter_output><empty_output><jupyter_text>For predictions till 2050<jupyter_code>df = pd.read_csv("epa-sea-level.csv", float_precision="legacy")
plt.figure(1, figsize=(16, 9))
plt.scatter(df["Year"], df["CSIRO Adjusted Sea Level"], c= "r")
regress = linregress(df["Year"], df["CSIRO Adjusted Sea Level"])
last_year = df["Year"].max()
df = df.append([{"Year": y} for y in range(last_year + 1, 2050)])
plt.plot(df["Year"],regress.intercept + regress.slope * df["Year"],c="r",label="fit all")
df_recent = df.loc[(df["Year"] >= 2000) & (df["Year"] <= last_year)]
bestfit = linregress(df_recent["Year"], df_recent["CSIRO Adjusted Sea Level"])
df_recent = df_recent.append([{"Year": y} for y in range(last_year + 1, 2050)])
plt.plot(df_recent["Year"],bestfit.intercept + bestfit.slope * df_recent["Year"],c="b",label="fit recent")
plt.xlabel("Year")
plt.ylabel("Sea Level (inches)")
plt.title("Rise in Sea Level")
plt.gca()
plt.savefig('sea_level_plot.png')
def draw_plot():
    # Read data from file
    df = pd.read_csv("epa-sea-level.csv", float_precision="legacy")

    # Create scatter plot
    plt.figure(1, figsize=(16, 9))
    plt.scatter(df["Year"], df["CSIRO Adjusted Sea Level"], c= "r")

    # Create first line of best fit
    regress = linregress(df["Year"], df["CSIRO Adjusted Sea Level"])
    last_year = df["Year"].max()
    df = df.append([{"Year": y} for y in range(last_year + 1, 2050)])
    plt.plot(df["Year"],regress.intercept + regress.slope * df["Year"],c="r",label="fit all")

    # Create second line of best fit
    df_recent = df.loc[(df["Year"] >= 2000) & (df["Year"] <= last_year)]
    bestfit = linregress(df_recent["Year"], df_recent["CSIRO Adjusted Sea Level"])
    df_recent = df_recent.append([{"Year": y} for y in range(last_year + 1, 2050)])
    plt.plot(df_recent["Year"],bestfit.intercept + bestfit.slope * df_recent["Year"],c="b",label="fit recent")

    # Add labels and title
    plt.xlabel("Year")
    plt.ylabel("Sea Level (inches)")
    plt.title("Rise in Sea Level")
    
    # Save plot and return data for testing (DO NOT MODIFY)
    plt.savefig('sea_level_plot.png')
    return plt.gca()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15122706168472252, 'fraction_numerical': 0.0568206942294937, 'mean_word_length': 5.8649468892261005, 'pattern_counts': {'":': 4, '<': 23, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '436840', 'license': 'Apache-2.0', 'n_tokens_mistral': 1891, 'n_tokens_neox': 1663, 'n_words': 420, 'path': 'free-code-camp-data-analysis-with-python.ipynb', 'repo_name': 'ADVAIT135/FreeCodeCamp-Data-Analytics-with-Pyhton', 'size': '4523'}