【问题标题】:Pandas scatterplot returns error when trying to pass a list for colorPandas 散点图在尝试传递颜色列表时返回错误
【发布时间】:2015-11-27 23:24:16
【问题描述】:

我正在使用 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)

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

【问题讨论】:

  • 使用 Pandas 0.16.2 为我工作。你用的是哪个版本?
  • 0.15.0,我来更新!
  • 我也把seed(0)改成了np.random.seed(0)

标签: python pandas colors dataframe scatter


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2018-10-24
    • 1970-01-01
    • 2021-04-15
    • 2020-11-03
    • 2019-01-23
    • 2015-05-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多