Ipython Settings

In [ ]:
#-------------------------------------------------------------------------------
# ipython settings
%reload_ext autoreload
%autoreload 2
%matplotlib inline

#-------------------------------------------------------------------------------
## change from scientific notation to decimal point in pandas
pd.set_option('display.float_format', lambda x: '%.0f' % x)

## Font Setting
plt.rcParams['font.sans-serif'] = ('Helvetica', 'Arial', 'Open Sans', 'Bitstream Vera Sans')

#-------------------------------------------------------------------------------
#Limiting floats output to 3 decimal points
pd.set_option('display.float_format', lambda x: '{:.3f}'.format(x))

#-------------------------------------------------------------------------------
##Ignore warnings
import warnings; warnings.filterwarnings('ignore')

Show Image in notebook

In [ ]:
<img src="./plots/green_taxi.jpg" alt="Drawing" style="width: 500px;"/>

Show Video in notebook

In [ ]:
from IPython.display import HTML
HTML("""
<video width="750" height="675" controls>
  <source src="./video/nyc_trips.mp4" type="video/mp4">
</video>
""")

Display Progress bar

In [ ]:
from tqdm import tqdm_notebook
from time import sleep

for i in tqdm_notebook(range(100)):
    sleep(0.01)

Run SQL queries in Pandas

In [ ]:
# import warnings; warnings.filterwarnings('ignore')
from pysqldf import SQLDF; 
sqldf = SQLDF(globals()); q = getattr(sqldf, 'execute')

Styling tables in Notebook

Different color based on value in Column

In [ ]:
def over_10M(value):
    if value > 10**7:
        color = 'green'
    else:
        color = 'blue'        
    return 'color: %s' % color

df.style.applymap(over_10M, subset=['AmountInUSD'])\
        .format({'AmountInUSD': "$ {:}"})

Color Gradient based on value in Column

In [ ]:
cm_table = sns.light_palette("red", as_cmap=True)

null_count =  pd.DataFrame(data.isnull().sum(), columns=['Missing Value Count'])
null_count.style.background_gradient(subset=['Missing Value Count'],
                               cmap=cm_table)

Drag and Drop Visualization (like Tableau)

In [ ]:
# Tableau like drag and drop
from pivottablejs import pivot_ui
pivot_ui(df)

temp_time = df[(df.lpep_pickup_datetime.dt.hour == hour_low) | (df.lpep_pickup_datetime.dt.hour <= hour) &\
            (df.lpep_pickup_datetime.dt.minute >= minute_low) & (df.lpep_pickup_datetime.dt.minute <= minute)]