0

I'm stuck on how to add the data values to bar plot in pandas. I've been searching how to do this for several hours now and am finally turning to stack overflow.

I wrote:

# 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)

I'd like to be able to show the values of the counts of y and n, floating just above the tops of teh bars, centered. How do I plot the values of the df?

aks85
  • 695
  • 3
  • 11
  • 24
  • 1
    I think you should take a look at the answer to the [question in this post](https://stackoverflow.com/questions/30228069/how-to-display-the-value-of-the-bar-on-each-bar-with-pyplot-barh). – Samuel Nde Oct 04 '18 at 04:22
  • THIS is what I've been searching for! THANK YOU! – aks85 Oct 04 '18 at 04:22
  • You are welcome. Could you mark your question as a duplicate question before someone else does and reduces your stack overflow score? – Samuel Nde Oct 04 '18 at 04:24
  • Found answer here, thanks to user above: https://stackoverflow.com/questions/30228069/how-to-display-the-value-of-the-bar-on-each-bar-with-pyplot-barh – aks85 Oct 04 '18 at 04:28

0 Answers0