Pandas option_context: Temporarily change display settings

Pandas option_context: Temporarily change display settings

Want to set an option in Python Pandas, but just temporarily? You can use option_context:

with pd.option_context('display.precision', 2):
    print(s/3)

Within the “with” block, the display precision is 2. But outside — before or after — it is the default.