Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from glob import glob
# Step 1: export to hdf5 chunks
for i, chunk in enumerate([pd.read_csv(file) for file in glob('folder/path')]):
df_chunk = vaex.from_pandas(chunk, copy_index=False)
df_chunk.export_hdf5(f'bigfile_part_{i}.hdf5')
df = vaex.open('bigfile_part_*.hdf5')
# Step 2: Combine back into one big hdf5 file
# Step 1: export to hdf5 chunks
for i, chunk in enumerate(pd.read_csv('bigfile.csv', chunksize=1_000_000)):
df_chunk = vaex.from_pandas(chunk, copy_index=False)
df_chunk.export_hdf5(f'bigfile_part_{i}.hdf5')
df = vaex.open('bigfile_part_*.hdf5')
# Step 2: Combine back into one big hdf5 file
df.export_hdf5('bigfile.hdf5')
" enable syntax highlighting
syntax enable
" show line numbers
set number
" set tabs to have 4 spaces
set ts=4
" indent when moving to the next line while writing code
def pi():
# Number of darts that land inside.
inside = 0
# Total number of darts to throw.
total = 1000000
# Iterate for the number of darts.
for i in range(0, total):
inside += is_inside()
import math as m
def is_inside():
x2 = r.random()**2
y2 = r.random()**2
# Increment if inside unit circle.
if m.sqrt(x2 + y2) < 1.0:
return 1
else:
# Challenge no 2: you have a list of names, and you want to find out which names are both long AND have a high percentage of vowels in them.
names = ['Maria', 'Leila', 'Karim', 'Jon', "Kalimero", "John", "Armstrong", "Braztchniev", "Mougandae"]
name_lengths = [len(w) for w in names]
relative_lengths = [l / max(lengths) for l in name_lengths]
vowel_counts = [sum([Counter(name)[v] for v in "aoeui"]) for name in names]
vowel_perc = [vc / l for vc, l in zip(vowel_counts, name_lengths)]
# Challenge no 1: you have a list of sentences. What are the top-3 most frequent words (case-insensitive) longer than 3 characters.
from collections import Counter
sentences = ["This is the first sentence", "My first time was in Havana", "What is it this time", "Time is precious"]
words = [word.lower() for sentence in sentences for word in sentence.split()]
counter = Counter([word for word in words if len(word) >= 3])
counter.most_common(3)
from pyo import *
s = Server().boot()
# downloaded from sampleswap
first = 'boomy-dirty-kick.wav'
second = 'CP_set1.wav'
third = 'bunchakiks17.wav'
tab1 = SndTable(first)
from pyo import *
s = Server().boot()
# Drops the gain
s.amp = 0.1
# Ramp up of amplitude. From 0.0 to 1.0 in 2 seconds
amp = SigTo(value=1, time=2.0, init=0.0)