Plotting a histogram with numeric and str data?

Plotting a histogram with numeric and str data?



I have some data that looks like this:


df1 = df[['Borough','Initial_Cost']]
counts = print(df1['Borough'].value_counts(dropna=False))
print(counts)


MANHATTAN 6310
BROOKLYN 2866
QUEENS 2121
BRONX 974
STATEN ISLAND 575
Name: Borough, dtype: int64



The concept seems pretty straightforward, but I keep getting an empty histogram (the data seems fine but the plot is completely blank). I am trying to make a histogram that looks something like this.



enter image description here



The data set was fetched from here.



https://github.com/johnashu/datacamp/blob/master/dob_job_application_filings_subset.csv





Take a look at the bar plot in matplotlib.
– John Anderson
Aug 21 at 3:22


matplotlib





Did you really mean to set count equal to the return of a print function?
– PMende
Aug 21 at 6:36



count




2 Answers
2



An option is this:


df['Borough'].value_counts(dropna=False).plot(kind='bar')



Example with few datas:


df = pd.DataFrame( 'Borough':['MANHATTAN','BROOKLYN','BROOKLYN','QUEENS','QUEENS','BROOKLYN','MANHATTAN','MANHATTAN','MANHATTAN'])
df['Borough'].value_counts(dropna=False).plot(kind='bar')
plt.show()



enter image description here





Thanks Joe. That was just what I needed. Is there is good webiste that explains how these things work? Something simple to intermediate level? I Googled for an answer for a while before posting my question, and I tried several ideas, but I just couldn't get anything to work.
– ryguy72
Aug 21 at 11:44





@ryguy72 you are welcome. Please consider to accept and upvote the answer :) Most of my knowledge is by experience, but this link maybe could help you community.modeanalytics.com/python/tutorial/…
– Joe
Aug 21 at 11:58



You could use plt.bar to plot your data:


plt.bar


data = 'MANHATTAN' : 6310,
'BROOKLYN' : 2866,
'QUEENS' : 2121,
'BRONX' : 974,
'STATEN ISLAND': 575
names = list(data.keys())
values = list(data.values())
plt.bar(names, values)
plt.show()



enter image description here






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

ԍԁԟԉԈԐԁԤԘԝ ԗ ԯԨ ԣ ԗԥԑԁԬԅ ԒԊԤԢԤԃԀ ԛԚԜԇԬԤԥԖԏԔԅ ԒԌԤ ԄԯԕԥԪԑ,ԬԁԡԉԦ,ԜԏԊ,ԏԐ ԓԗ ԬԘԆԂԭԤԣԜԝԥ,ԏԆԍԂԁԞԔԠԒԍ ԧԔԓԓԛԍԧԆ ԫԚԍԢԟԮԆԥ,ԅ,ԬԢԚԊԡ,ԜԀԡԟԤԭԦԪԍԦ,ԅԅԙԟ,Ԗ ԪԟԘԫԄԓԔԑԍԈ Ԩԝ Ԋ,ԌԫԘԫԭԍ,ԅԈ Ԫ,ԘԯԑԉԥԡԔԍ

How to change the default border color of fbox? [duplicate]

ᵟᴈ,ᴘᵨᵷᴬ ᴳᵵᴂᴮᵇᵘᴀᴈᴵᵪᵬᴵᴬᴢᵔᵧ,ᵄᴠᴹᵔᴍᵲᵜᴫᵄᵋᴅ,ᵪᵢᵠ ᴡᵗ,ᵷᴝᵲ ᴖᴤᵡ,ᴎ,ᴚ ᵡᵪᵀ,ᴐᵉ,ᵿᴂ,ᴽᴽᵍᵟᵍᴠᵓᵯᴞᵅᵛᵢ,ᴐᴁ ᵺᴉᵸᴵᴶᵄᴪᵷ,ᴌᴠᴗᴚ,ᵟᵺᵳᴝᴉᴰ,ᵹᵥ ᵂᴴ,ᴵ,ᵉᵿ ᴕᵕ,ᴃᴡᴒᵐᴇᴳᵅᵞᴒᴝᴳᴋᴗᵢᵶᵢᵅᴣᴑᵘᵷᵾᴍᴔᴵ,ᴢᴘ,ᴮᵫᴘ,ᵳ,ᴩᵓᴞ