#python #data-analysis
Вопрос:
Пожалуйста, помогите мне. Новичок в этой области и спрашиваю 1-й раз на этой платформе.
Мой код
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
xpoints=df["Years"]
ypoints=df["CSIRO Adjusted Sea Level"]
plt.scatter(xpoints, ypoints)
# Create first line of best fit
res= linregress(xpoints,ypoints)
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_df=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
plt.xlabel("Year")
plt.ylabel("Sea Level (inches)")
plt.title("Rise in Sea Level")
plt.legend(fontsize="medium")
plt.show()
# Save plot and return data for testing (DO NOT MODIFY)
plt.savefig('sea_level_plot.png')
return plt.gca()
Ошибка:
точки x=df[«Годы»]
^
Ошибка отступа: неожиданный отступ
Ссылка на мой реплит : https://replit.com/@LavishSinghal/boilerplate-sea-level-predictor-1#sea_level_predictor.py
Комментарии:
1. Они имеют отступ в 1 пробел. Нажмите кнопку backspace и переместите их влево
2. Выровняйте по вертикали 3 строки ниже # Создайте точечную диаграмму со строкой, которая предшествует этому комментарию