How to run IPython magic from a script

It depends on which version of IPython you have. If you have 1.x: from IPython import get_ipython ipython = get_ipython() If you have an older version: import IPython.core.ipapi ipython = IPython.core.ipapi.get() or import IPython.ipapi ipython = IPython.ipapi.get() Once that’s done, run a magic command like this: ipython.magic(“timeit abs(-42)”) Note: The script must be run via … Read more

My plot in ipython does not show with pyplot.show()

If I set my backend to template in ~/.matplotlib/matplotlibrc, then I can reproduce your symptoms: ~/.matplotlib/matplotlibrc: # backend : GtkAgg backend : template Note that the file matplotlibrc may not be in directory ~/.matplotlib/. In this case, the following code shows where it is: >>> import matplotlib >>> matplotlib.matplotlib_fname() In [1]: import matplotlib.pyplot as p … Read more

Auto-Loading a module on IPython startup

i’ve found a solution to this one, in your IPython profile directory (by default – .ipython\profile_default), edit the file ipython_config.py (create it with ipython profile create if it does not exist) with the following lines: # loads the root config object c=get_config() # executes the line in brackets on program launch c.InteractiveShellApp.exec_lines = [‘from __future__ … Read more

How can I left justify text in a pandas DataFrame column in an IPython notebook

If you’re willing to use another library, tabulate will do this – $ pip install tabulate and then from tabulate import tabulate df = pd.DataFrame ({‘Text’: [‘abcdef’, ‘x’], ‘Value’: [12.34, 4.2]}) print(tabulate(df, showindex=False, headers=df.columns)) Text Value —— ——- abcdef 12.34 x 4.2 It has various other output formats also.