Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
Requires node.js and npm.
First, do npm install -g ijavascript.
Then run ijs once.
autoenv): Read!| # defaultdict use case | |
| # Finding a Pareto front, where (x1, x2) is a list of tuples satisfying | |
| # e.g. (x1, x2) : |df[(df[var1 > x1]) & df[var2 > x2)]| < 0.1|df|, | |
| # where |df| is the size of df, i.e., df.shape[0] (in Pandas) | |
| pareto = defaultdict(lambda: np.Inf) | |
| for x1, x2 in xs: | |
| pareto[x1] = min(pareto[x1], x2) |
To count occurrences when aggregating (e.g. in pivot_table), use len as aggfunc!
To drop a row: Cheatsheet
df[df.name != 'Tina']df.drop(df.index[2])c['a'].shift(periods=1)
pandoc file.md -o file.pdf
current_date - interval '1 days'*extract(isodow from now()) sunday before this weekGiven array a, count occurrences and stack.
e.g. a = np.array([0, 0, 1, 1, 2, 1, 0, 2, 3, 0, 1])
then counts = np.dstack(np.unique(a, return_counts=True)) gives
array([[[0, 4],
[1, 4],
[2, 2],
tee from itertools is cool! linkfrom itertools import tee
i, j = tee(data)
next(j)
for first, second in zip(i, j):