I hereby claim:
- I am milo0 on github.
- I am milo0 (https://keybase.io/milo0) on keybase.
- I have a public key ASAqn1wF5KMGkvNvjpY9IlULdDb0H4ucexTqCLm6Jlkvrwo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
import pandas as pd | |
with open('table.txt') as f: | |
content = f.readlines() | |
columns = content.pop(0) | |
content_list = [row.split() for row in content] | |
df = pd.DataFrame(columns=columns, data=content_list) |
def concatenate_per_row(A, B): | |
m1,n1 = A.shape | |
m2,n2 = B.shape | |
out = np.zeros((m1, m2, n1+n2), dtype=A.dtype) | |
out[:, :, :n1] = A[:, None, :] | |
out[:, :, n1:] = B | |
return out.reshape(m1*m2, -1) |
import itertools, sys | |
from time import sleep | |
spinner = itertools.cycle(['|', '/', '-', '\\']) | |
while True: | |
sys.stdout.write(next(spinner)) # write the next character | |
sys.stdout.flush() # flush stdout buffer (actual character display) | |
sys.stdout.write('\b') # erase the last written char | |
sleep(0.1) |
def merge_dfs(df1, df2): | |
"""Merge two DataFrames. Common columns among the dfs are reduced to one.""" | |
res = pd.merge(df1, df2, how='outer', left_index=True, right_index=True) | |
cols = sorted(res.columns) | |
pairs = [] | |
for col1, col2 in zip(cols[:-1], cols[1:]): | |
if col1.endswith('_x') and col2.endswith('_y'): | |
pairs.append((col1, col2)) | |
for col1, col2 in pairs: | |
res[col1[:-2]] = res[col1].combine_first(res[col2]) |
def extract_integers(string): | |
extracted_ints = [int(s) for s in string.split() if s.isdigit()] | |
return extracted_ints | |
def extract_floats(string): | |
floats = [] | |
for s in string.split(): | |
try: | |
extracted_floats.append(float(s)) |