typeError 帮助,plt.scatter 将我的 .csv 读取为 true/false 而不是数值

typeError help, plt.scatter reading my .csv as true/false rather than numerical values

我正在关注这个 article,当我收到此错误时,我试图使用我自己的数据来绘制客户的订单数量与其生命周期支出的关系:

我尝试从我的数据框中删除 true/false 值并更新相关包

TypeError                                 Traceback (most recent call last)
<ipython-input-74-221045cec1a1> in <module>
      3 y_means = km4.fit_predict(X)
      4 #Visualizing the clusters for k=4
----> 5 plt.scatter(X[y_means==0,0],X[y_means==0,1],s=50, c='purple',label='Cluster1')
      6 plt.scatter(X[y_means==1,0],X[y_means==1,1],s=50, c='blue',label='Cluster2')
      7 plt.scatter(X[y_means==2,0],X[y_means==2,1],s=50, c='green',label='Cluster3')

/anaconda3/lib/python3.6/site-packages/pandas/core/frame.py in __getitem__(self, key)
   2925             if self.columns.nlevels > 1:
   2926                 return self._getitem_multilevel(key)
-> 2927             indexer = self.columns.get_loc(key)
   2928             if is_integer(indexer):
   2929                 indexer = [indexer]

/anaconda3/lib/python3.6/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   2655                                  'backfill or nearest lookups')
   2656             try:
-> 2657                 return self._engine.get_loc(key)
   2658             except KeyError:
   2659                 return self._engine.get_loc(self._maybe_cast_indexer(key))

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

TypeError: '(array([ True,  True,  True, ...,  True,  True,  True]), 0)' is an invalid key```



Update: After following the advice in the comments and changing my plt.scatter to `plt.scatter(X[y_means==0][:,0],X[y_means==0][:,1],`

I receive the error `TypeError: '(slice(None, None, None), 0)' is an invalid key`

尝试在 pandas.dataframe 上使用 numpy 技术时出现问题 我使用 X=X.value 对其进行了转换并且有效

using Your error code here 

y_means = km4.fit_predict(X)
# solution, convert the dataframe to a np.array
#Visualizing the clusters for k=4
X = np.array(X) #that all
plt.scatter(X[y_means==0,0],X[y_means==0,1],s=50, c='purple',label='Cluster1')
plt.scatter(X[y_means==1,0],X[y_means==1,1],s=50, c='blue',label='Cluster2')
plt.scatter(X[y_means==2,0],X[y_means==2,1],s=50, c='green',label='Cluster3')

导入数据集后使用X = X.values