简体   繁体   English

如何从特定 DataFrame 列的条形图中 plot 值

[英]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.

相关问题 如何使用熊猫从数据框中绘制(分组)条形图 - How to plot a (grouped) bar chart from a dataframe using pandas 如何从 dataframe 到 plot 在 x 中包含多个列的分组条形图? - How to plot a grouped bar chart from a dataframe with several columns in x? 如何根据第一个 dataframe 列的值更改条形图的 xticks? - How to change xticks of bar chart according to values of first dataframe column? 如何用条形图绘制条形图? - How to plot a bar chart with bar values? 如何在Bokeh中绘制“分组依据”数据框作为条形图 - how to plot a “group by” dataframe in Bokeh as Bar chart 如何在条形图中从一列列表中获取 plot 词频 - How to plot word frequency, from a column of lists, in a bar chart 如何 plot 从 object dataframe 列中的 Z23EEEB4347BDD2576BFC6B7EE9AB 中的饼图? - How to plot a pie chart from an object dataframe column in python? 从matplotlib中的选定列绘制条形图 - plot a bar chart from a selected column in matplotlib 如何从熊猫数据框中按降序条形图对值进行排序 - How to sort values in descending order bar plot from pandas dataframe 如何在带有误差线的条形图中绘制熊猫数据框的特定行和列(基于行名和列名)? - How to plot specific rows and columns of pandas dataframe (based on name of row and name of column) in bar plot with error bars?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM