Django0602
Django0602

Reputation: 807

Plot multiple column counts by a single column at x axis in python

I have a data frame where there are 5 columns that have comments on different topics. I want to plot the count of all such columns by a target variable team so that I can have a all the plots available at once.

The dataframe looks like this :

Function             Accountability   Reward    Pay    Others
Services             Abc               Abc      Abc    Abc
Manufacturing .      NA                NA       NA     NA
Digital Technology   DEF               DEF      DEF   DEF
Services             Abc               Abc      Abc    Abc
Manufacturing .      NA                NA       NA     NA
Digital Technology   DEF               DEF      DEF   DEF

Now there are 2 comments for Services under accountability and so on. So,I want to create multiple plots in one code that shows the count of all the comments by Function. I DO NOT want to have one bar chart that shows everything. I want different bar charts that shows count of each comment column by function separately.

Upvotes: 0

Views: 773

Answers (1)

Farooq Sk
Farooq Sk

Reputation: 124

Is this what you are looking for ?

import pandas as pd 
import matplotlib.pyplot as plt 
plt.rcParams['figure.figsize'] = (15,5)

# Your table has been read to 'df' 

df1 = df.drop('Function', axis=1)

plt.subplot(1,3,1)
df1[df.Function == 'Services'].count().plot.bar()
plt.title('Services')

plt.subplot(1,3,2)
df1[df.Function == 'Digital Technology'].count().plot.bar()
plt.title('Digital')

plt.subplot(1,3,3)
df1[df.Function == 'Manufacturing.'].count().plot.bar()
plt.title('Manufacturing')

Plot

Upvotes: 2

Related Questions