How it works...
We sorted the values of a variable into user-defined intervals using the Boston House Prices dataset. We first plotted a histogram of the LSTAT variable, to get an idea of the range of values of the variable. Next, we arbitrarily determined and captured the limits of the intervals in a list: we created intervals that vary from 0-10, 10-20, 20-30, and more than 30, by setting the upper limit to infinite with np.Inf. Next, we created a list with the interval names as strings.
Using pandas' cut() method and passing the list with the interval limits, we sorted the variable values into the pre-defined bins. We executed the command twice; in the first run, we set the labels argument to the list that contained the label names as ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access