Skip to content

Instantly share code, notes, and snippets.

View fabsta's full-sized avatar

Fabian Schreiber fabsta

View GitHub Profile
@fabsta
fabsta / reading_data.md
Last active December 5, 2017 17:40
Reading data #deeplearning #InputOutput

minst

from keras.datasets import mnist
(X_train, y_train), (X_test, y_test) = mnist.load_data()
(X_train.shape, y_train.shape, X_test.shape, y_test.shape)
>> ((60000, 28, 28), (60000,), (10000, 28, 28), (10000,))

X_test = np.expand_dims(X_test,1)
X_train = np.expand_dims(X_train,1)
@fabsta
fabsta / python_for_list.py
Last active January 27, 2020 14:28
[python iterate list] Iterate through a python list #python #pandas
# list = [1, 3, 5, 7, 9]
# Using for loop
for i in list:
print(i)
# 1
# 3
# for index
for i in range(length):
print(list[i])
@fabsta
fabsta / pandas_read_csv.py
Created January 27, 2020 14:25
[pandas read csv] read in a csv file #python
# often works
df = pd.read_csv('file.csv')
df = pd.read_csv('file.csv', header=0, index_col=0, quotechar='"',sep=':', na_values = ['na', '-', '.', ''])
# specifying "." and "NA" as missing values in the Last Name column and "." as missing values in Pre-Test Score column
df = pd.read_csv('../data/example.csv', na_values={'Last Name': ['.', 'NA'], 'Pre-Test Score': ['.']})
# skipping the top 3 rows
df = pd.read_csv('../data/example.csv', na_values=sentinels, skiprows=3)
# interpreting "," in strings around numbers as thousands separators
df = pd.read_csv('../data/example.csv', thousands=',')
@fabsta
fabsta / pandas_columns_to_dict.py
Created January 27, 2020 14:28
[pandas columns to dict] converts two columns to a dictionary #python #pandas
area_dict = dict(zip(lakes.area, lakes.count))