0

I think my problem is easy to solve but I just cannot find a solution.

I want to make a horizontal stacked bar chart with Matplotlib/Pandas using this data. The csv-file contains the answers from a questionnaire. "Q4" contains values from 1-7. 6 and 7 are supposed to be missing values.

missing = {"Q4":[6,7]}
df = pd.read_csv("my_file.csv", sep=";", na_values=missing)

I want to plot the value counts of "Q4" by using something like this.

df["Q4"].value_counts()

The output is this:

1.0    2906
2.0    1508
3.0     738
4.0     206
5.0     154

My plot should consist of one horizontal column showing the value counts of value 1-5 as a stacked bar.

user
  • 5,370
  • 8
  • 47
  • 75
NK_
  • 361
  • 1
  • 4
  • 11

1 Answers1

6

Let's try this:

df['Q4'].plot(kind='barh')

enter image description here

Another option is:

df[['Q4']].T.plot(kind='barh', stacked=True)

enter image description here

CezarySzulc
  • 1,849
  • 1
  • 14
  • 30