尝试传递颜色列表时,Pandas scatterplot会返回错误

时间:2015-11-27 23:24:16

标签: python pandas colors dataframe scatter

我正在使用sklearn boston数据集。以下是我操纵数据的方法:

from sklearn.datasets import load_boston
from random import shuffle
boston = load_boston()
seed(0)  # Creates a replicable shuffling
new_index = range(boston.data.shape[0])
shuffle(new_index) # shuffling the index
X, y = boston.data[new_index], boston.target[new_index]
df = pd.DataFrame(X, columns=boston.feature_names)

colors = ['k' if v > np.mean(y) else 'w' for v in y]

scatter = df.plot(kind='scatter', x='RM', y='LSTAT', c=colors)

我收到一条错误,指出“unhashable type:'list'”。我不确定是什么问题,特别是因为我从我正在使用的python书中得到了这个代码(Python for Data Science for Dummies)。知道为什么这个散点图不起作用吗?

1 个答案:

答案 0 :(得分:0)

答案是我使用的是旧版熊猫。更新到pandas 0.17.0后,问题得到了解决。