This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def house_price_in_aus_from_model(usd_per_floor, | |
usd_per_bathroom_squared, | |
floor_count, | |
bathroom_count, | |
usd_to_aus_rate): | |
""" | |
Calculate the house price in Australian dollars from | |
a polynomial regression model | |
""" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PIXEL_NORMALIZATION_FACTOR = 12.5 | |
PIXEL_OFFSET_FACTOR = 150 | |
for row_index in range(row_count): | |
for column_index in range(column_count): | |
for color_channel_index in range(color_channel_count): | |
normalized_pixel_value = ( | |
original_pixel_array[row_index][column_index][color_channel_index] | |
* PIXEL_NORMALIZATION_FACTOR | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(['base/js/namespace', 'base/js/events'], function (Jupyter, events) { | |
// Template cells including markdown and imports | |
var setUp = function () { | |
Jupyter.notebook.insert_cell_at_index('markdown', 0) | |
.set_text(`# Introduction | |
State notebook purpose here`) | |
Jupyter.notebook.insert_cell_at_index('markdown', 1).set_text(`### Imports | |
Import libraries and write settings here.`) | |
// Define imports and settings | |
Jupyter.notebook.insert_cell_at_index('code', 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
# Pandas options | |
pd.options.display.max_columns = 30 | |
pd.options.display.max_rows = 20 | |
from IPython import get_ipython | |
ipython = get_ipython() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def show_stats_by_tag(tag): | |
return(df.groupby(f'<tag>{tag}').describe()[['views', 'reads']]) | |
stats = interact(show_stats_by_tag, | |
tag=widgets.Dropdown(options=['Towards Data Science', 'Education', | |
'Machine Learning', 'Python', 'Data Science'])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create widgets | |
directory = widgets.Dropdown(options=['images', 'nature', 'assorted']) | |
images = widgets.Dropdown(options=os.listdir(directory.value)) | |
# Updates the image options based on directory value | |
def update_images(*args): | |
images.options = os.listdir(directory.value) | |
# Tie the image options to directory value | |
directory.observe(update_images, 'value') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create interactive version of function with DatePickers | |
interact(stats_for_article_published_between, | |
start_date=widgets.DatePicker(value=pd.to_datetime('2018-01-01')), | |
end_date=widgets.DatePicker(value=pd.to_datetime('2019-01-01'))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Correlation between two columns with dropdown | |
@interact | |
def correlations(column1=list(df.select_dtypes('number').columns), | |
column2=list(df.select_dtypes('number').columns)): | |
print(f"Correlation: {df[column1].corr(df[column2])}") | |
# Stats of a column with dropdown | |
@interact | |
def describe(column=list(df.columns)): | |
print(df[column].describe()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Interact with specification of arguments | |
@interact | |
def show_articles_more_than(column=['claps', 'views', 'fans', 'reads'], | |
x=(10, 100000, 10)): | |
return df.loc[df[column] > x] |
NewerOlder