Skip to content

Instantly share code, notes, and snippets.

View GeorgeSeif's full-sized avatar

George GeorgeSeif

View GitHub Profile
(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([])
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
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)
# Horizontal concat
pd.concat([features_1to5_df, features_6to10_df, features_11to15_df], axis=1)
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))
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",
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))
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))
df = df.stack()
print(df)
"""
0 Player Superman
Year 2000
Points 23
1 Player Batman
Year 2000
groups_df = df.groupby('Player')
for player, group in groups_df:
print("----- {} -----".format(player))
print(group)
print("")
### This prints out the following
"""
----- Batman -----