Skip to content

Instantly share code, notes, and snippets.

@mattwigway
Created June 28, 2019 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattwigway/241d8b30f07dcaa8059242f9e6528310 to your computer and use it in GitHub Desktop.
Save mattwigway/241d8b30f07dcaa8059242f9e6528310 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Load the file referenced in the first argument into a Jupyter QtConsole as df
# change to appropriate conda environment
source activate py37
tempscript=`mktemp`
tee "$tempscript" <<EOF
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# triple quotes for safety
filename = '''$1'''
if filename.endswith('.csv'):
df = pd.read_csv(filename)
elif filename.endswith('.tsv'):
df = pd.read_csv(filename, sep='\t')
elif filename.endswith('.xls') or filename.endswith('.xlsx'):
df = pd.read_excel(filename)
elif filename.endswith('.dta'):
df = pd.read_stata(filename)
elif filename.endswith('.feather'):
df = pd.read_feather(filename)
else:
raise ValueError(f'cannot determine file type of {filename}!')
EOF
PYTHONSTARTUP=$tempscript jupyter qtconsole
rm $tempscript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment