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
(train_images, train_labels), (test_images, test_labels) = datasets.mnist.load_data() | |
class_names = ['zero', 'one', 'two', 'three', 'four', 'five', | |
'six', 'seven', 'eight', 'nine'] | |
plt.figure(figsize=(10,10)) | |
for i in range(16): | |
plt.subplot(4, 4, i+1) | |
plt.xticks([]) | |
plt.yticks([]) |
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 tensorflow as tf | |
from tensorflow.keras import datasets, layers, models, optimizers | |
import matplotlib.pyplot as plt | |
if tf.__version__ < "2.0.0": | |
!pip install --upgrade tensorflow_gpu==2.0 |
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 | |
players_data = {'Player': ['Superman', 'Batman', 'Thanos', 'Batman', 'Thanos', | |
'Superman', 'Batman', 'Thanos', 'Black Widow', 'Batman', 'Thanos', 'Superman'], | |
'Year': [2000,2000,2000,2001,2001,2002,2002,2002,2003,2004,2004,2005], | |
'Points':[23,43,45,65,76,34,23,78,89,76,92,87]} | |
df = pd.DataFrame(players_data) | |
print(df) |
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
# Horizontal concat | |
pd.concat([features_1to5_df, features_6to10_df, features_11to15_df], axis=1) |
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 membership_map(pandas_series, groups_dict): | |
groups = {x: k for k, v in groups_dict.items() for x in v} | |
mapped_series = pandas_series.map(groups) | |
return mapped_series | |
mapped_data = membership_map(foods, groups_dict) | |
print(list(mapped_data)) |
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 | |
foods = pd.Series(["Bread", "Rice", "Steak", "Ham", "Chicken", | |
"Apples", "Potatoes", "Mangoes", "Fish", | |
"Bread", "Rice", "Steak", "Ham", "Chicken", | |
"Apples", "Potatoes", "Mangoes", "Fish", | |
"Apples", "Potatoes", "Mangoes", "Fish", | |
"Apples", "Potatoes", "Mangoes", "Fish", | |
"Bread", "Rice", "Steak", "Ham", "Chicken", | |
"Bread", "Rice", "Steak", "Ham", "Chicken", |
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
from itertools import product | |
import pandas as pd | |
import numpy as np | |
col_names = ["Day", "Month", "Year"] | |
df = pd.DataFrame(list(product([10, 11, 12], [8, 9], [2018, 2019])), | |
columns=col_names) | |
df['data'] = np.random.randn(len(df)) |
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
from itertools import product | |
import pandas as pd | |
import numpy as np | |
col_names = ["Day", "Month", "Year"] | |
df = pd.DataFrame(list(product([10, 11, 12], [8, 9], [2018, 2019])), | |
columns=col_names) | |
df['data'] = np.random.randn(len(df)) |
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
df = df.stack() | |
print(df) | |
""" | |
0 Player Superman | |
Year 2000 | |
Points 23 | |
1 Player Batman | |
Year 2000 |
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
groups_df = df.groupby('Player') | |
for player, group in groups_df: | |
print("----- {} -----".format(player)) | |
print(group) | |
print("") | |
### This prints out the following | |
""" | |
----- Batman ----- |