3

Is there a way to specify Pandas and NumPy display width on startup of an IPython shell. For example,

# Run this at startup
import numpy as np
np.set_printoptions(linewidth=200)

import pandas as pd
pd.options.display.width = 200
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Kapil Sharma
  • 1,412
  • 1
  • 15
  • 19
  • Here is for pandas : http://stackoverflow.com/questions/21249206/how-to-configure-display-output-in-ipython-pandas – imranal May 27 '16 at 16:16
  • It is not clear to me that the Pandas config will let you do all of this. It may be easier to just use the PYTHONSTARTUP environmental variable: http://stackoverflow.com/questions/11124578/automatically-import-modules-when-entering-the-python-or-ipython-interpreter – andrew May 27 '16 at 16:25
  • @andrew The link you provided also had a way to put a startup script in .ipython profile directory as shown in the answer below. Thanks – Kapil Sharma May 27 '16 at 17:22
  • Great. I was thinking more along the lines of the IPython profiles and configurations. But the solution below accomplishes the same thing as using PYTHONPATH. http://ipython.readthedocs.io/en/stable/config/intro.html?highlight=config – andrew May 27 '16 at 17:44

2 Answers2

3

For Windows, for me, I have a startup directory:

'C:\Users\username\.ipython\profile_default\startup'

In this I create a file:

'00-script.py`

Files in this directory will be run in alphabetical order by name. I put '00' in front to ensure it gets run first. In this file, you'd put:

import numpy as np
np.set_printoptions(linewidth=200)

import pandas as pd
pd.options.display.width = 200

Check documentation to see where your directory is.

Documentation

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
piRSquared
  • 285,575
  • 57
  • 475
  • 624
1

Just to add to the answer by @piRSquared, on Unix-based systems, you can do it by putting a startup script in ~/.ipython/profile_default/startup:

$ cat ~/.ipython/profile_default/startup/load_pdnp.py 
import pandas as pd
import numpy as np

pd.options.display.width = 200
np.set_printoptions(linewidth=200)

Or ~/.ipython/profile_<name>/startup for a specific profile.

This has a side effect that pd and np would be now available to you in the IPython shell.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Kapil Sharma
  • 1,412
  • 1
  • 15
  • 19