Skip to content

Instantly share code, notes, and snippets.

View AdamGold's full-sized avatar
🌏
Trust the process

Adam Goldschmidt AdamGold

🌏
Trust the process
  • Israel
View GitHub Profile
In [16]: import itertools
In [17]: list(itertools.combinations([1, 2, 3, 4], 2))
[(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]
In [9]: import array
In [10]: import pickle
In [11]: double_array = array.array("i", range(10 ** 6))
...: start_time = time.time()
...: with open("array_temp.bin", "wb") as f:
...: double_array.tofile(f)
...: array_end_time = time.time() - start_time
In [12]: int_list = list(range(10 ** 6))
...: start_time = time.time()
...: with open("list_temp.bin", "wb") as f:
In [6]: import collections
In [7]: Article = collections.namedtuple("Article", ["title", "description", "id"])
In [8]: Article(title="Python is cool.", id=1, description="")
Article(title='Python is cool.', description='', id=1)
In [2]: import typing
In [3]: class BetterLookingArticle(typing.NamedTuple):
...: title: str
...: id: int
...: description: str = "No description given."
...:
In [4]: BetterLookingArticle(title="Python is cool.", id=1)
BetterLookingArticle(title='Python is cool.', id=1, description='No description given.')
@AdamGold
AdamGold / gist:c0f6e05eb434a9327f80f7d13cd43386
Last active October 28, 2018 20:15
SQLAlchemy Load CSV Files
# from MODELS_MODULE import MODEL
import pandas as pd
CSV_FOLDER = 'csvs'
def load_csv(file, model_name):
df = pd.read_csv('{}/{}.csv'.format(CSV_FOLDER, file))
csv = df.where((pd.notnull(df)), None) # replace Nan with None
for row in csv.itertuples(index=False):