如何将数据值添加到熊猫df.plot(kind ='bar')列?

时间:2018-10-04 04:05:19

标签: python pandas plot bar-chart

我被困在如何将数据值添加到熊猫的条形图中。我一直在搜索如何执行此操作几个小时,现在终于转向堆栈溢出。

我写道:

# import data and packages 

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc
%matplotlib inline 

df = pd.read_csv('2018_ms_data_impact_only_10_2_18.csv', low_memory=False)
df.head()

ExternalReference   interest_el interest_pl interest_ad interest_ol commitment_elected  commitment_policy   commitment_advocacy commitment_organizing   timeline_elected    ... Policy  Organizing  Engagement  Parent  Veteran first_gen_american  first_gen_college   ri_region   LGBTQ   Gender
0   0034000001RHCU0AAP  1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 Woman
1   00340000015yDbOAAU  1.0 1.0 1.0 2.0 0.0 0.0 0.0 2.0 0.0 ... 0.0 1.0 2.0 0.0 0.0 0.0 0.0 1.0 0.0 Man
2   0034000000y3QjMAAU  1.0 2.0 2.0 2.0 0.0 2.0 3.0 4.0 0.0 ... 5.0 2.0 3.0 0.0 0.0 0.0 0.0 1.0 0.0 Man
3   0034000001qcNXRAA2  1.0 1.0 1.0 3.0 0.0 0.0 0.0 3.0 0.0 ... 0.0 1.0 6.0 0.0 0.0 0.0 0.0 1.0 0.0 Woman
4   0034000001DVPedAAH  1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 Woman


# plot question
df['impact_action_yn']
ax = df['impact_action_yn'].value_counts().plot(kind= 'bar', figsize = (6,6))

# add some text for labels, title and axes ticks
ax.set_ylabel('Count')
ax.set_title('Taken an Impact Action in the Last 12 Months')
ax.set_xticklabels(('No', 'Yes'));

df.plot(kind=bar)

我希望能够显示y和n的计数值,它们正好浮动在th条的顶部上方。如何绘制df的值?

0 个答案:

没有答案