Automation of standard imported jupyter / ipython laptops

For at least 99% of my jupyter / ipython laptops, I use the following imports:

import pandas as pd from pandas.io.json import json_normalize import matplotlib.pyplot as plt import matplotlib as mpl import numpy as np from bson import json_util, ObjectId import json from datetime import datetime, timedelta import pytz pd.set_option('max_columns', 50) mpl.style.use('ggplot') %pylab inline 

Has anyone found any solution that would allow me to do this automatically or create some kind of macro?

+7
ipython ipython-notebook jupyter
source share
2 answers

Yes, you can do this with custom startup scripts. Mines are in /Users/user_name/.ipython/profile_default/startup . The scripts must be python rated files ( .py ), and automatic import should go there.

The document is here .

If you want to have %pylab inline in your start script, the script must be saved with the .ipy extension to indicate that this ipython script is not a regular python script. I don't think this will work correctly if you have cellular magic like %pylab inline in a regular python script.

+14
source share

I like to use% load magic. Create a file with all the import, leave it in the home directory and start the laptop using

 %load my_imports.py 

This method allows you to edit the import before starting it.

+3
source share

All Articles