TypeError: must be str, not float - linear Regression

TypeError: must be str, not float - linear Regression

当我从之前的图表中复制代码并更新变量时,我收到一个类型错误:必须是 str,而不是浮点数的线性回归错误。以下是我的依赖项以及代码。 (slope, intercept) 线是错误指向的地方。任何帮助表示赞赏。我对编码还很陌生,似乎无法弄清楚这一点。

import pandas as pd
import numpy as np
import requests
import time
import json
import random
import scipy.stats as st

from sklearn import datasets
from scipy.stats import linregress
from pprint import pprint```


x_values = city_data.loc[city_data['Latitude']>=0]
y_values = city_data['Temperature']

(slope, intercept, rvalue, pvalue, stderr) = stats.linregress(x_values, y_values)
regress_values = x_values * slope + intercept
line_eq = "y = " + str(round(slope,2)) + "x + " + str(round(intercept,2))

plt.scatter(x_values, y_values, marker="o", facecolors="green", edgecolors="black",
            s=30, alpha=0.75)
plt.plot(x_values,regress_value,"r-")
plt.annotate(line_eq,(20,36),fontsize=15,color="red")
plt.xlim(-50, 85)
plt.ylim(10,95 )
plt.title('City Norther Hemisphere Latitude vs Temperature (10/10/2020)')
plt.xlabel('Latitude')
plt.ylabel('Tempurature (F)')
plt.show()```

将此行更改为:

city_data = city_data[city_data['Latitude']>=0]
x_values = city_data['Latitude']