如何为pandas数据帧的所有列制作两个单独的Seaborn kdeplots:
([A-z])\-([A-z])
Match the regex below and capture its match into backreference number 1 «([A-z])»
Match a single character in the range between “A” and “z” «[A-z]»
Match the character “-” literally «\-»
Match the regex below and capture its match into backreference number 2 «([A-z])»
Match a single character in the range between “A” and “z” «[A-z]»
\1 \2
Insert the text that was last matched by capturing group number 1 «\1»
Insert the character “ ” literally « »
Insert the text that was last matched by capturing group number 2 «\2»
): df
我尝试了以下代码,但这不起作用。以下代码的任何提示?
df.columns = ["A", "B", "C", "D", "E", "F"]
答案 0 :(得分:2)
你的问题在这里:
dependencies.*[^}]
ax(i) = sns.kdeplot(dftouse[column], c = colorUp(dftouse[column]))
是函数调用。你正试图给它分配一些东西。这是不正确的。
我不熟悉matplotlib,只是Python。也许你的意思是ax(i)
?如果ax是一个数组或一个dict,那么这可能是正确的。
答案 1 :(得分:2)
我认为你需要使用pd.melt
:
df = pd.DataFrame({'id1' :np.random.randint(3,size=1000),
'id2' :['ABC'[i] for i in np.random.randint(3,size=1000)],
'val1':np.random.normal(loc=1, size=1000),
'val2':np.random.normal(loc=2, size=1000),
'val3':np.random.normal(loc=3, size=1000)})
g = sns.FacetGrid(pd.melt(df,
id_vars=['id1','id2'],
value_vars=['val1','val2','val3']),
hue='id1',col='id2',row='variable')
g.map(sns.kdeplot,'value')