Change default options in pandas
configuration, ipython, pandas, python
Solution
Have a look at the docs:
Using startup scripts for the python/ipython environment to import pandas and set options makes working with pandas more efficient. To do this, create a .py or .ipy script in the startup directory of the desired profile. An example where the startup folder is in a default ipython profile can be found at:
$IPYTHONDIR/profile_default/startup
More information can be found in the ipython documentation. An example startup script for pandas is displayed below:
import pandas as pd
pd.set_option('display.max_rows', 999)
pd.set_option('precision', 5)
(or use the new form `pd.options.display.max_rows = 999`).
You also asked:
-- is there any way to only run the pandas code when I import pandas from within ipython? it takes quite a while to import pandas, so I'd rather not do it every time I launch a new ipython instance
As a workaround, you could import pandas in the background. See Import python modules in the background in REPL.
Problem
I'm wondering if there's any way to change the default display options for pandas. I'd like to change the display formatting as well as the display width each time I run python, eg: ``` pandas.options.display.width = 150 ``` I see the defaults are hard-coded in `pandas.core.config_init`. Is there some way in pandas to do this properly? Or if not, is there some way to set up ipython at least to change the config each time I import pandas? Only thing I can think of is making my own mypandas library that wraps pandas with some extra commands issued each time it's loaded. Any better ideas?