Python 无效的RGBA参数:nan

Python 无效的RGBA参数:nan,python,matplotlib,plot,graph,colors,Python,Matplotlib,Plot,Graph,Colors,我试图用5种不同的颜色显示散点图:每个“地区一种”。不幸的是,我出现了这个错误:无效的RGBA参数:nan 我的数据框如下所示: > price surface district > 0 1850 46 1.0 > 1 1900 41 4.0 > 2 1925 55 4.0 > 3 1960

我试图用5种不同的颜色显示散点图:每个“
地区一种”。不幸的是,我出现了这个错误:
无效的RGBA参数:nan

我的数据框如下所示:

>         price    surface    district  
>     0    1850       46          1.0
>     1    1900       41          4.0
>     2    1925       55          4.0
>     3    1960       52          2.0
>     4    2025       57          3.0
>     5    2055       60         10.0    
     ...    ...       ...         ...
{1.0: 'red', 2.0: 'pink', 3.0: 'limegreen', 4.0: 'violet', 10.0: 'cyan'}
以下是我所做的:

colors =['red', 'pink', 'limegreen', 'violet', 'cyan']

color_dict = dict(zip(np.unique(house['district']),colors))
因此,颜色词汇表如下所示:

>         price    surface    district  
>     0    1850       46          1.0
>     1    1900       41          4.0
>     2    1925       55          4.0
>     3    1960       52          2.0
>     4    2025       57          3.0
>     5    2055       60         10.0    
     ...    ...       ...         ...
{1.0: 'red', 2.0: 'pink', 3.0: 'limegreen', 4.0: 'violet', 10.0: 'cyan'}
然后我创建了一个变量col:

col = house['district'].map(color_dict)
最后,我画了一幅图:

df.plot(kind = 'scatter', x = 'surface', y = 'price', c = col)

有人能解释一下这里的问题是什么吗?

因此,似乎在我的数据帧中的某个地方存在Nan值,尽管我没有发现它们。 正如@coldspeed所建议的,我只需要调用df.dropna()


我真可耻!;)

所以,在我的数据帧中似乎有Nan值,尽管我没有发现它们。 正如@coldspeed所建议的,我只需要调用df.dropna()


我真可耻!;)

如果您的数据帧有NaN值,为什么不直接调用
df.dropna()
?确实,您必须在某个地方有NaN值。仅基于您目前提供的数据,我无法复制您的问题。如果您的数据帧具有NaN值,为什么不调用
df.dropna()
?确实,您必须在某个地方具有NaN值。仅根据您目前提供的数据,我无法复制您的问题。