在条形图中以条形显示值

时间:2019-11-18 13:29:59

标签: python pandas dataframe

我的数据帧的列(C_NC)包含两个值,即C和NC。我用

绘制了C和NC值的频率

df['C_NC'].value_counts().plot(kind='bar')

enter image description here

尽管此图很好,但我也想在条形图中的每个条形上都有确切的频率编号。我对使用Pandas Dataframe进行数据可视化还很陌生。有没有办法用pandas dataframe做到这一点?

1 个答案:

答案 0 :(得分:1)

使用:

s=df['C_NC'].value_counts()
s.plot(kind='bar',yticks=s)

示例

您在这里看到的是相同的问题:

import numpy as np
import matplotlib.pyplot as plt
s1=pd.Series(np.random.randint(0,2,300))
s=s1.value_counts()
print(s)


1    156
0    144
dtype: int64

s1.value_counts().plot(kind='bar')

enter image description here


我们现在可以显示确切的值

s.plot(kind='bar',yticks=s)

enter image description here