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()


CPU times: user 4.87 s, sys: 0 ns, total: 4.87 s
Wall time: 4.87 s
Out[19]:
3.1404184

In [27]:
%%time 
estimate_pi()


CPU times: user 4.89 s, sys: 11.8 ms, total: 4.9 s
Wall time: 4.92 s
Out[27]:
3.1409752

In [27]:
%timeit estimate_pi()


4.92 s ± 75.8 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

In [27]:
%prun estimate_pi()


 

In [30]:
%lprun -f estimate_pi estimate_pi()

In [30]:
%memit estimate_pi()


UsageError: Line magic function `%memit` not found.

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