I have a pandas dataframe df
with two columns (type
and IR
) as this one:
type IR
0 a 0.1
1 b 0.3
2 b 0.2
3 c 0.8
4 c 0.5
...
I want to plot three distributions (one for each type
) with the values of the IR so, I write:
sns.displot(df, kind="kde", hue='type', rug=True)
but I get this error: The following variable cannot be assigned with wide-form data 'hue'
Any idea?
EDIT:
My real dataframe looks like
pd.DataFrame({"type": ["IR orig", "IR orig", "IR orig", "IR trans", "IR trans", "IR trans", "IR perm", "IR perm", "IR perm", "IR perm", "IR perm"],
"IR": [1.41, 1.42, 1.32, 0.0, 0.44, 0.0, 1.41, 1.31, 1.41, 1.37, 1.34]
})
but with sns.displot(df, x='IR', kind="kde", hue='type', rug=True)
I got ValueError: cannot reindex on an axis with duplicate labels
CodePudding user response:
Use:
df = pd.DataFrame({'type': {0: 'a', 1: 'b', 2: 'b', 3: 'c', 4: 'c'},
'IR': {0: 0.1, 1: 0.3, 2: 0.2, 3: 0.8, 4: 0.5}})
print (df)
type IR
0 a 0.1
1 b 0.3
2 b 0.2
3 c 0.8
4 c 0.5
sns.displot(df.reset_index(drop=True), x='IR', kind="kde", hue='type', rug=True)