Data Analysis with Python Projects - Sea Level Predictor

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:

This is the dependency problem with the python data analysis projects discussed and solved in many posts in the forums and you’ll need to follow the solutions there. If you can’t fix it, then you will have to post a link to a repl for debugging as import errors are not due to your code but rather the modules available on the system.

Also, please post errors in code blocks as text so that others may find them by searching since images are not searchable.

Hi M,
Great that you placed your error messages among the text. :+1:
As I see it, the 9th line: 'ModuleNotFoundError: No module named ‘pandas’ ’
seems the most informative.

  1. Sometimes I run the “import” modules over and over again because my kernel gets interrupted often.
  2. Also check the software versions too, that can make sure you are loaded properly.
  3. BTW, noticed the code after your function 'def draw_plot(): is not indented, I wasn’t sure if that was just a copy/paste or viewing issue.
    HTH

It happened to me a lot. It’s annoying,
but my simple fix is to go to the “shell” (it should be beside the “console” tab u have)
or u can access it through tool → shell at the left side bar.

It will look like command prompt/console.
just run

pip install pandas

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