使用matplotlib python的UFuncTypeError,如何解决?

我现在正在使用Machine Learning方法来学习K-Means,但是使用matplotlib进行可视化时会出现一些错误。有人可以帮忙吗?

代码在这里

url = 'https://pokemondb.net/pokedex/all'
header = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/50.0.2661.75 Safari/537.36','X-Requested-With': 'XMLHttpRequest'}
r = requests.get(url,headers=header)
df = pd.read_html(r.text,header=0)[0]
df.rename(columns={'Sp. Atk':'SpAtk','Sp. Def':'SpDef'},inplace=True)
df.to_csv('data_pokemon.csv',index=False)

raw_data = df.iloc[:,5:7]

x_array = np.array(raw_data)
k_means = KMeans(n_clusters=3,random_state=200)
k_means.fit(x_array)
df['Cluster'] = k_means.labels_.astype('int64')

plt.scatter(df['Attack'],df['Defense'],s = 20,c = df['Cluster'],marker='o',alpha='0.5')
plt.title('Clustering K-Means')
plt.xlabel('Attack')
plt.ylabel('Defense')
plt.show()

当我尝试将其可视化为分散点时,出现错误

UFuncTypeError: ufunc 'clip' did not contain a loop with signature matching types (dtype('<U11'),dtype('<U11'),dtype('<U11')) -> dtype('<U11')
<figure size 432x288 with 1 Axes>

相关文章

功能概要:(目前已实现功能)公共展示部分:1.网站首页展示...
大体上把Python中的数据类型分为如下几类: Number(数字) ...
开发之前第一步,就是构造整个的项目结构。这就好比作一幅画...
源码编译方式安装Apache首先下载Apache源码压缩包,地址为ht...
前面说完了此项目的创建及数据模型设计的过程。如果未看过,...
python中常用的写爬虫的库有urllib2、requests,对于大多数比...