This file contains hidden or 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
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)] |
This file contains hidden or 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
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: |
This file contains hidden or 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
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) |
This file contains hidden or 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
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.') |
This file contains hidden or 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 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): |
NewerOlder