Pandas and NumPy default width change on startup

回眸只為那壹抹淺笑 提交于 2019-12-13 14:46:59

问题


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

回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/37488043/pandas-and-numpy-default-width-change-on-startup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!