[英]How to plot values in a bar chart from a specific DataFrame column
Shown below are few rows in the DataFrame and these are the columns 'Category', 'Content Rating' and 'Reviews'.下面显示的是 DataFrame 中的几行,它们是“类别”、“内容评级”和“评论”列。
Below shown is an extract taken from a particular DataFrame column "Content Rating".下面显示的是摘自特定 DataFrame 列“内容评级”的摘录。
In: pd.value_counts(Data['Content Rating']) #Considered the total value count from the df column
out: A 1000
B 918
C 360
D 305
E 3
F 1
And this is the extract taken to plot a bar char这是提取到 plot 一个条形字符
In: a = pd.value_counts(Data['Content Rating'])
a.plot(kind='bar')
Out:
I want to have the values in the bar char.我想在 bar char 中有值。
The resulting bar chart should look like this:生成的条形图应如下所示:
Try this:尝试这个:
for i, v in enumerate([x[0] for x in a.values.tolist()]):
plt.text(v + 3, i + .25, str(v), color='blue', fontweight='bold')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.