Skip to content

Instantly share code, notes, and snippets.

View GeorgeSeif's full-sized avatar

George GeorgeSeif

View GitHub Profile
### Adding big DataFrames in Pandas
pandas_df + pandas_df + pandas_df + pandas_df + pandas_df
### Adding big DataFrames in Dask
dask_df + dask_df + dask_df + dask_df + dask_df
### Filtering by price in Pandas
pandas_df[pandas_df["price"] > 250]
### Filtering by price in Dask
dask_df[dask_df["price"] > 250]
### Calculate mean using pandas
pandas_df["price"].mean()
### Calculate mean using Dask
dask_df["price"].mean()
import dask.dataframe as dd
import pandas as pd
dask_df = dd.read_csv("stock_data.csv")
dask_df = dask_df.repartition(partition_size="100MB")
pandas_df = pd.read_csv("stock_data.csv")
import random
import pandas as pd
NUM_ROWS = 1000000
symbols = ["AAPL", "GOOG", "AMZN", "NFLX", "MSFT"]
prices = [random.randint(1, 500) for _ in range(50)]
def generate_random_stock_data(symbols, prices):
return {"symbol": random.sample(symbols, 1)[0],
test_loss, test_accuracy = model.evaluate(test_images, test_labels, verbose=2)
print('\nTest accuracy = {0:.2f}%'.format(test_accuracy*100.0))
plt.plot(history.history['accuracy'], label='accuracy')
plt.plot(history.history['val_accuracy'], label='val_accuracy')
plt.xlabel('Epoch')
plt.ylabel('Accuracy')
plt.ylim([0.7, 1])
plt.legend(loc='best')
plt.plot(history.history['loss'], label='loss')
plt.plot(history.history['val_loss'], label='val_loss')
plt.xlabel('Epoch')
adam = optimizers.Adam(lr=0.0001)
model.compile(adam, loss='categorical_crossentropy', metrics=["accuracy"])
history = model.fit(train_images, train_labels, epochs=10,
validation_data=(test_images, test_labels))
train_images = train_images.reshape(60000, 28, 28, 1).astype('float32') / 255.0
test_images = test_images.reshape(10000, 28, 28, 1).astype('float32') / 255.0
train_labels = tf.keras.utils.to_categorical(train_labels, 10)
test_labels = tf.keras.utils.to_categorical(test_labels, 10)
IMG_SIZE = (28, 28, 1)
input_img = layers.Input(shape=IMG_SIZE)
model = layers.Conv2D(32, (3, 3), padding='same')(input_img)
model = layers.Activation('relu')(model)
model = layers.Conv2D(32, (3, 3), padding='same', strides=(2, 2))(model)
model = layers.Activation('relu')(model)
model = layers.Conv2D(64, (3, 3), padding='same')(model)
model = layers.Activation('relu')(model)