Some shortcuts
Here’s the table of contents:
- Read a txt file as a list
- Chunks from a list
- Change directory
- Min max normalize np array
- tar a directory, use split and send files with rclone
- Get rows with same string from pandas dataframe
Read a txt file as a list
with open('file.txt') as f:
lines = f.readlines()
Chunks from a list
def chunks(lst, n):
"""Yield successive n-sized chunks from lst."""
for i in range(0, len(lst), n):
yield lst[i:i + n]
Change directory
import os
os.chdir(path)
Min max normalize np array
import numpy as np
normalized = (x-np.min(x))/(np.max(x)-np.min(x))
tar a directory, use split and send files with rclone
tar cf big_file.tar big_file/ &
split -b 1024M ./big_file.tar big_file.tar.part &
or
tar cf - big_file | split --bytes=1024MB - big_file_tar/big_file.tar. &
and
time rclone -vv --opendrive-chunk-size=32000k --checkers=4 --transfers=8 --buffer-size=32000M copy big_file_tar/ opendrive:root/big_file_tar &> big_file.out &
Get rows with same string from pandas dataframe
df.loc[df['column_name'] == "string"]