gpt4 book ai didi

python - 值错误: "color kwarg must have one color per dataset"

转载 作者:行者123 更新时间:2023-12-01 07:08:41 25 4
gpt4 key购买 nike

我有一个关于 eBay 上的一些二手车的数据集,我在编辑数据集后尝试绘制该数据集,如下所示:

import pandas as pd

df = pd.read_csv("./autos.csv.bz2", encoding = "iso8859-1")
df = df.drop(["dateCrawled", "abtest", "dateCreated", "nrOfPictures", "lastSeen", "postalCode", "seller", "offerType"], axis = 1)

import numpy as np

df["monthOfRegistration"] = np.where(df["monthOfRegistration"] == 0, 6, df["monthOfRegistration"])


df["registration"] = df["yearOfRegistration"] + (df["monthOfRegistration"] - 1) / 12

df = df.drop(["yearOfRegistration", "monthOfRegistration"], axis = 1)


df = df.drop(df[df["price"] == 0].index)
df = df.drop(df[df["powerPS"] == 0].index)


print(df["notRepairedDamage"].unique())
print(df["notRepairedDamage"])

df["notRepairedDamage"] = np.where(df["notRepairedDamage"] == "ja", 1, df["notRepairedDamage"])
df["notRepairedDamage"] = np.where(df["notRepairedDamage"] == "nein", 0, df["notRepairedDamage"])


df = df[df["notRepairedDamage"].notnull()]

我尝试使用 seaborn.pairplot 使用 matplotlib 绘制数据,但出现以下错误:

ValueError: color kwarg must have one color per dataset

我只得到前 3 行相对频率的图,所有其他图都是空的,还有第 4 行和第 5 行的相对频率。

Matplotlib seaborn, example image

df = df[(df["price"] < 100000) & (df["powerPS"] < 2000)

from IPython import get_ipython
get_ipython().run_line_magic('matplotlib', 'inline')

import seaborn as sns

g = sns.pairplot(df)

我认为编辑数据集时确实出了问题。有谁可以帮助我吗?那太好了!非常感谢!

最佳答案

在您的评论之后,有一个示例片段,希望对您有所帮助。也许问题出在 IPython 上?不幸的是,我不知道。提供可用的数据集肯定会有所帮助。

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns

a = pd.DataFrame()
a['One'] = [1, 3, 3, 2, 1]
a['Two'] = ['ja', 'ja', 'nein', 'ja', 'nein']
a['Two'] = np.where(a['Two'] == 'ja', 1, a['Two'])
a['Two'] = np.where(a['Two'] == 'nein', 0, a['Two'])
a = a[a['Two'].notnull()]
print(a)
sns.pairplot(a)
plt.show()

这会打印

   One Two
0 1 1
1 3 1
2 3 0
3 2 1
4 1 0

并显示

enter image description here

关于python - 值错误: "color kwarg must have one color per dataset",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58329965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com