This file contains 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
import pendulum | |
now = pendulum.now() | |
now.format('YYYYMMDD_HHmm') |
This file contains 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
# See | |
# https://stackoverflow.com/questions/3207219/how-do-i-list-all-files-of-a-directory | |
from os import listdir | |
from os.path import isfile, join | |
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))] |
This file contains 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
# See | |
# https://stackoverflow.com/questions/8384737/extract-file-name-from-path-no-matter-what-the-os-path-format | |
import ntpath | |
path_to_file = r"C:\a\b\s\d\f_a\aasdas_o_g.json" | |
print(ntpath.basename(path_to_file) | |
# Output: |
This file contains 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
import json | |
import os | |
import pytest as pt | |
# See Python Testing with pytest. > Chapter 4 > Using tmpdir and tmpdir_factory | |
class TestStuff(object): | |
@pt.fixture(scope='class') |
This file contains 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
import os | |
import pathlib | |
# 1 | |
# ------------------------------------------------- | |
os.environ["ALLUSERSPROFILE"] | |
# The environment variable "ALLUSERSPROFILE" is available on Windows only. | |
# On Windows returns | |
# 'C:\\ProgramData' |
This file contains 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
import fnmatch | |
pattern = "aaa_*" # Special characters '*' and '?' | |
list_of_all_files = ['aaa_1.json', 'a.json', 'b.json'] | |
for filename in list_of_all_files: | |
if fnmatch.fnmatch(filename, pattern): | |
print(filename) |
This file contains 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
import matplotlib.pyplot as plt | |
from matplotlib import gridspec | |
import mplcursors | |
annotations0 = ['cat', 'dog', 'hare'] | |
x = [1, 2, 3] | |
y = [0, 2.5, 3] | |
fontsize=20 |
This file contains 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
import numpy as np | |
def find_index_of_first_nonzero_occurrence(array): | |
""" | |
Find the index of the first non-zero occurrence in a numpy array. | |
This is essentially a wrapper around np.flatnonzero(). If there are | |
no non-zero values None is returned. | |
array (numpy array): Should be 1d array and all elements should be numeric | |
""" |
This file contains 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
# Sometimes timeseries need to be concatenated and then sorted so that the time vector is monotonic. | |
# ---- Monotonic in x, but not strictly increasing | |
# ******************************************************************************** | |
x1 = np.array([1, 2, 3, 4, 4]) # Not all of the values are unique | |
y1 = np.array([10, 20, 30, 42, 40]) | |
x2 = np.array([1.5, 2.5, 3.5, 4.5]) | |
y2 = np.array([15, 25, 35, 45]) | |
x_ = np.concatenate((x1, x2)) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
OlderNewer