-1

I need to plot a graph between various attributes of my dataset ans all I know as per my current knowledge is histogram, and in that I can take only one variable.

I tried with this simple code:

sn.catplot(x="CDR", y="Age", hue="M/F", data=df);
plt.title('Distribution of Age by CDR rate')

This is the Error I'm getting

CDR is Clinical Dementia Rating.
I do have code in R language ,they have 1st grouped them all and then plotted the graph but I found that even more complecated so I decided to go with this way.

This is the type of graph I need.

I am clueless about this error. I tried df.CDR, df.age, df.M/F and that is giving error due to name "M/F".

'DataFrame' object has no attribute 'M'

I tried changing name in dataset but that's giving even more errors.

If R code is required

Help!!!! df.head()

  • Please do not post code/data/error messages as images on SO, post it directly here on SO as text. See also: [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) and [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Mr. T Dec 29 '20 at 11:20
  • As for the error, maybe related: https://stackoverflow.com/q/32908315 – Mr. T Dec 29 '20 at 11:24
  • https://idownvotedbecau.se/imageofcode https://idownvotedbecau.se/imageofanexception/ – Mr. T Dec 29 '20 at 12:37

1 Answers1

0

In Python, use seaborn.violinplot

https://seaborn.pydata.org/generated/seaborn.violinplot.html

Full example below (from seaborn doc):

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

sns.set_theme(style="whitegrid")

tips = sns.load_dataset("tips")

df = pd.DataFrame([[0.0, 0.0, 0.0, 0.2, 0.2, 0.2, 0.2], [87, 88, 89, 60, 55, 58, 59],
                   ["M", "M", "F", "F", "F", "F", "M"]]).T
df.columns = ["CDR", "Age", "M/F"]

df = df.astype({"CDR": "float64", "Age": "int64"}) # Update type

sns.violinplot(x="CDR", y="Age", hue="M/F", data=df)
plt.show()
thibaultbl
  • 886
  • 1
  • 10
  • 20