Histograms in Pandas
<p>Relatively new to python and pandas. I have a dataframe: <code>df</code> with say 2 columns (say, <code>0</code> and <code>1</code>) and n rows. I'd like to plot the histograms of the two time series data represented in the two columns. I also need access to the exact counts in the histogram for each bin for later manipulations.</p>

<pre><code>b_counts, b_bins = np.histogram(df[0], bins = 10)
a_counts, a_bins = np.histogram(df[1], bins = 10)

plt.bar(b_bins, b_counts)
plt.pbar(a_bins, a_counts)
</code></pre>

<p>However I get an error for incompatible sizes, i.e, length of the bins array is 11 whereas the length of counts array is 10. Two questions:
1) Why does the histogram in numpy an extra bin? i.e., 11 instead of 10 bins
2) Assuming question 1) above can be solved, is this the best/simplest way of going about this?</p>

<p>I would directly use Pyplot's built in <a href="http://matplotlib.org/1.2.1/examples/pylab_examples/histogram_demo.html" rel="nofollow">histogram</a> function:</p>

<pre><code>b_counts, b_bins, _ = plt.hist(df[0], bins = 10)
a_counts, a_bins, _ = plt.hist(df[1], bins = 10)
</code></pre>

<hr>

<p>As per the documentation of <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html" rel="nofollow">numpy.histogram</a> (if you scroll down far enough to read the <code>Returns</code> section in parameter definition):</p>

<blockquote>
  <p><strong>hist</strong> : <em>array</em> The values of the histogram. See density and weights for
  a description of the possible semantics.</p>
  
  <p><strong>bin_edges</strong> : <em>array of dtype
  float</em> Return the bin edges <code>(length(hist)+1)</code>.</p>
</blockquote>

<p>Quite clear, isn't it?</p>

python pandas numpy histogram bins