13 Configuring pandas

 

This chapter covers

  • Configuring pandas display settings for both the Notebook and single cells
  • Limiting the number of printed DataFrame rows and columns
  • Altering the precision of decimal-point numbers
  • Truncating a cell’s text content
  • Rounding numeric values when they fall below a floor

As we’ve worked through the book’s data sets, we’ve seen how pandas improves our user experience by making sensible decisions on data presentation. When we output a 1,000-row DataFrame, for example, the library assumes that we’d prefer to see 30 rows from the beginning and end rather than the whole data set, which can clutter the screen. Sometimes, we may want to break from pandas’ assumptions and alter its settings to fit our custom display needs. Luckily, the library exposes many of its internal settings for us to alter. In this chapter, we’ll learn how to configure options such as row and column limits, floating-point precision, and value rounding. Let’s get our hands dirty and see how we can switch things up.

13.1 Getting and setting pandas options

We’ll begin by importing the pandas library and assigning it an alias of pd:

In  [1] import pandas as pd

13.2 Precision

13.3 Maximum column width

13.4 Chop threshold

13.5 Option context

Summary