0

I am VERY new to Python, and I am looking for a solution to my problem. In particular, I need to return the max value of the bins in my historgram...and am at a loss on how to proceed. My dataframe is a pandas dataframe as:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

df = pd.read_csv(filename)

bin_array = np.linspace(start=0., stop=10., num=150)
df.series.hist(bins=bin_array)

Thanks in advance.

DavidG
  • 24,279
  • 14
  • 89
  • 82
Kevin Dow
  • 21
  • 1
  • 7
  • Special Thanks go to David G ( https://stackoverflow.com/users/5851928/davidg) for properly formatting my post! – Kevin Dow Mar 06 '18 at 12:42
  • 2
    Also related https://stackoverflow.com/questions/17148787/are-there-functions-to-retrieve-the-histogram-counts-of-a-series-in-pandas. Highly likely to be cleaner to use numpy function directly to produce the histogram info, then plot if needed. – Bonlenfum Mar 06 '18 at 13:04
  • Yep, almost definitely better to use `numpy` – DavidG Mar 06 '18 at 13:13
  • David G, THANKS! I missed that post in my search - and it was exactly what I needed! – Kevin Dow Mar 06 '18 at 13:14

1 Answers1

2

You may want to just use numpy's histogram function directly. It is what pandas is calling behind the scenes to generate the plot.

bin_array = np.linspace(start=0., stop=10., num=150)
counts, bins = np.histogram(df.series, bins=bin_array)
James
  • 32,991
  • 4
  • 47
  • 70