Skip to content

Instantly share code, notes, and snippets.

View dlainfiesta's full-sized avatar
🏁
Pushing the envelope...

Diego Lainfiesta dlainfiesta

🏁
Pushing the envelope...
  • Guatemala, Guatemala
View GitHub Profile
@devhero
devhero / py_remote_extract_tar_gzip.py
Last active May 24, 2023 18:50
python download and extract remote file tar.gzip
# Instruct the interpreter to create a network request and create an object representing the request state. This can be done using the urllib module.
import urllib.request
import tarfile
thetarfile = "http://file.tar.gz"
ftpstream = urllib.request.urlopen(thetarfile)
thetarfile = tarfile.open(fileobj=ftpstream, mode="r|gz")
thetarfile.extractall()
# The ftpstream object is a file-like that represents the connection to the ftp server. Then the tarfile module can access this stream. Since we do not pass the filename, we have to specify the compression in the mode parameter.
@slchangtw
slchangtw / fill_zeros
Last active August 13, 2018 10:29
Filling zeros in time series data
import numpy as np
import pandas as pd
from datetime import datetime
# make an example
np.random.seed(0)
item = np.random.choice(['A', 'B'], 10)
year = np.random.choice([2016, 2017], 10)