Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
460 views
in Technique[技术] by (71.8m points)

python - ValueError: "color kwarg must have one color per dataset"

I have a dataset regarding some used cars from eBay, which I tried to plot after I edited the dataset as follows:

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()]

I tried to plot the data with matplotlib using seaborn.pairplot but got the following error:

ValueError: color kwarg must have one color per dataset

I do only get the plots with the relative frequencies of the first 3 lines, all the other graphs are empty, also relative frequencies in line 4 and 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)

I assume that something did go wrong when I edited my dataset. Is there anyone who could help me? That would be great! Thank you very much!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Following your comment, an example snippet, which hopefully can help you. Maybe the issue is with IPython? Unfortunately, I do not know. Having your dataset available would definitely help.

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()

This prints

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

and displays

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...