In [ ]:
%load_ext line_profiler
%load_ext heat
# automatically reload modules when they have changed
%load_ext autoreload
%autoreload 2
%whos
#See list of variables
In [16]:
from random import random
def estimate_pi(n=1e7) -> "area":
"""Estimate pi with monte carlo simulation.
Arguments:
n: number of simulations
"""
in_circle = 0
total = n
while n != 0:
prec_x = random()
prec_y = random()
if pow(prec_x, 2) + pow(prec_y, 2) <= 1:
in_circle += 1 # inside the circle
n -= 1
return 4 * in_circle / total
In [19]:
%time estimate_pi()
Out[19]:
In [27]:
%%time
estimate_pi()
Out[27]:
In [27]:
%timeit estimate_pi()
In [27]:
%prun estimate_pi()
In [30]:
%lprun -f estimate_pi estimate_pi()
In [30]:
%memit estimate_pi()
In [ ]:
%mprun -f estimate_pi estimate_pi()
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
%show all outputs
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
# Add themes
pip install jupyterthemes
jt -t chesterish
#jt -r
# Start with some imports!
from ipywidgets import interact, interact_manual
import ipywidgets as widgets
@interact
def show_articles_more_than(column='claps', x=5000):
return df.loc[df[column] > x]
%env CUDA_VISIBLE_DEVICES=''
import cufflinks as cf
@interact
def scatter_plot(
x=list(df.select_dtypes('number').columns),
y=list(df.select_dtypes('number').columns)[1:],
theme=list(cf.themes.THEMES.keys()),
colorscale=list(cf.colors._scales_names.keys())
):
df.iplot(
kind='scatter',
x=x,
y=y,
mode='markers',
xTitle=x.title(),
yTitle=y.title(),
text='title',
title=f'{y.title()} vs {x.title()}',
theme=theme,
colorscale=colorscale
)
%load_ext autoreload
%autoreload 1
#with pip
pip install qgrid
jupyter nbextension enable --py --sys-prefix qgrid
# only required if you have not enabled the ipywidgets nbextension yet
jupyter nbextension enable --py --sys-prefix widgetsnbextension
import qgrid
qgrid_widget = qgrid.show_grid(df, show_toolbar=True)
qgrid_widget
%load_ext sql_magic
import sqlalchemy
import pandas as pd
import sqlite3
from sqlalchemy import create_engine
sqlite_engine = create_engine('sqlite://')
%config SQL.conn_name = "sqlite_engine"
%config SQL
%config SQL.output_result = False
%%read_sql df
SELECT * FROM presidents
df
later_presidents = %read_sql SELECT * FROM presidents WHERE year_of_birth > 1825