Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automate standard jupyter/ipython notebook imports

For at least 99% of my jupyter/ipython notebooks 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 discovered any sort of solution that would allow me to do this automatically or create some sort of macro?

like image 904
metersk Avatar asked Aug 25 '15 18:08

metersk


1 Answers

I like to use the %load magic. Make a file with all the imports in, leave it in the home directory and start the notebook with

%load my_imports.py

This method lets you edit the imports before running them.

like image 163
Paul Brown Avatar answered Oct 21 '22 17:10

Paul Brown