1
votes

I'm trying to produce a bar chart to show the percentage of "Male","Female", and "different identity". So, I would like to have Male, Female, and Different Identity appear on the x axis and the percentage on the y axis.

This is my current code which I sourced from somewhere else

sns.barplot(x=ds.Gender, y=x, data = ds, estimator=lambda x: len(x) / len(ds) *100)

Currently, I get the output

"Neither the x nor y variable appears to be numeric."

I've tried to make the 'y' variable something numeric, but I have failed to do so. I've looked at countless other questions but couldn't implement them.

Any help would be much appreciated.

example of data frame

1
Can you show a couple of example rows of your dataframe? - sjc
I've since added a print screen of a portion of the data frame. - MrStewart

1 Answers

1
votes

You're already giving the barplot function the dataframe, so your x and y arguments can be strings matching columns in your frame. You're correct that the barplot will yield percentage on the y-axis with that estimator, and you can pass any numerical column as a dummy to y:

sns.barplot(x="Gender", y="Age", data=ds, estimator=lambda x: len(x) / len(ds) *100)