amc
amc

Reputation: 833

Pandas histogram with 2 columns and known frequencies

I have a dataframe df that looks like this:

    INDEX     VAL
0        1  23.0
1   250001  23.0
2   500001  23.0
3   750001  18.0
4  1000001   0.0

How can I plot a histogram where the x-axis has the index and y is the value of VAL, and the histogram bars are 1-250001, 250001-500001, etc?

So for example, from 1-250001 the bar should be at height 23.

Upvotes: 1

Views: 1164

Answers (1)

akuiper
akuiper

Reputation: 214987

Since you already have the frequency, what you need is a bar plot; You can adjust the plot parameters to make it look like a histogram:

import matplotlib
%matplotlib inline
ax = df.set_index('INDEX').plot(kind="bar", color="#dd55ff", position=0, width=1.0, rot=0)

enter image description here

Upvotes: 3

Related Questions