Skip to content

Instantly share code, notes, and snippets.

@nitred
Last active March 24, 2022 09:09
Show Gist options
  • Save nitred/f60ecb1d27c2786c8adf04f5d3d8ab29 to your computer and use it in GitHub Desktop.
Save nitred/f60ecb1d27c2786c8adf04f5d3d8ab29 to your computer and use it in GitHub Desktop.
Common jupyter notebook headers and imports for convenience.

Expand Width of Cell

from IPython.core.display import display, HTML
# Expand to 90% of screen width
display(HTML("<style>.container { width:90% !important; }</style>"))

Set max rows for pandas to display

import pandas as pd
pd.set_option('display.max_rows', 100)

Import custom package from source

import sys
custom_pkg_src = '/path/to/custom-pkg/'
if not custom_pkg_src in sys.path:
    sys.path.insert(0, custom_pkg_src)

Import site-packages from other environment

import sys
site_packages_src = '/home/USERNAME/anaconda3/envs/ENVNAME/lib/python3.6/site-packages/'
if not site_packages_src in sys.path:
    sys.path.insert(0, site_packages_src)

Import Data Science Imports

import matplotlib
%matplotlib notebook

from pprint import pprint

import pickle
import glob
import os
import datetime
import sys

import pandas as pd
import numpy as np
import scipy
import matplotlib.pyplot as plt

Describe

def describe(obj):
    from pprint as pprint
    
    print(type(obj))
    
    # If List
    if isinstance(obj, list):
        print(len(obj))
        
    # If Dict
    if isinstance(obj, dict):
        print(len(obj.keys()))
        if len(obj.keys()) < 20:
            pprint(obj.keys())

How to add a Kernel

#!/bin/bash
export PATH=/path/to/anaconda/bin:$PATH
conda create -n py36 -y python=3.6.3
source activate py36
ipython kernel install --user --name py36
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment