[英]Plotting a bar plot with seaborn in python
The data frame I am using: https://www.kaggle.com/mustiztemiz/diabetes我正在使用的数据框: https://www.kaggle.com/mustiztemiz/diabetes
I have the following column:我有以下专栏:
Outcome - which has values 0 or 1.结果- 值为 0 或 1。
I want to plot a barplot which has Outcome on the x-axis and the it's count on y-axis.我想 plot 一个条形图,它在 x 轴上有结果,在 y 轴上有计数。
My code is as follows:我的代码如下:
sns.barplot(x='Outcome', y=diabetes['Outcome'].value_counts(), data=diabetes)
It is returning the following plot它返回以下 plot
The output I got is wrong as 1 should be 268 in count and 0 should be 500 in count.我得到的 output 是错误的,因为 1 的计数应该是 268,而 0 的计数应该是 500。 I don't know where I did the mistake.
我不知道我在哪里做错了。
# encoding: utf-8
import pandas
import matplotlib.pyplot as plt
import seaborn as sns
diabetes = pandas.read_csv('diabetes.csv')
# solution one:
data = diabetes['Outcome'].value_counts()
sns.barplot(data.index, data.values)
# solution two:
sns.countplot(x='Outcome', data=diabetes)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.