Skip to content

Instantly share code, notes, and snippets.

View beatorizu's full-sized avatar
🤓
Focusing

beatorizu

🤓
Focusing
  • São José dos Campos, SP Brazil
  • 20:15 (UTC -03:00)
View GitHub Profile
from PIL import Image
# The main image
img_b = Image.open("tumblr_nv07r7pHRh1txa2z2o1_500.png")
# The potato seal image
img_l = Image.open("avatar_3ee88102fcff_128.png")
# Area to paste potato seal
area = (img_b.size[0] - img_l.size[0],
img_b.size[1] - img_l.size[1],
# OBMEP 2015 - 2ª Fase - Data
def sum_digit(number):
result = 0
while number:
result, number = result + number % 10, number // 10
return result
def reverse_number(number):
/* OBMEP 2015 - 2ª Fase - Data */
function sum_digit(number) {
var result = 0;
while (number) {
result += number % 10;
number = Math.floor(number / 10);
}
return result;
}
from pandas import DatetimeIndex, read_excel
# Essa planilha só tem um folha então vai retorna o DataFrame
sheets = read_excel('./BulletinSearch.xlsx')
# Pode agrupar para fazer max, min, sum e count
count_impact = sheets.groupby(by='Impact').count()
# Para agrupar datas tem que criar um obj DatetimeIndex
# Nesse DataFrame os dados já são diários, mas se fossem dados horários
@beatorizu
beatorizu / download_cleaner.py
Last active May 13, 2017 19:23
FTP download files cleaner
"""Clean downloaded files
Usage:
download_cleaner.py <ftpconfig_dir>
Arguments:
<ftpconfig_dir> Path to ftpconfig directories
Options:
-h, --help Show this screen
def find_nearest_point(latitude, longitude, l_latitude, l_longitude):
"""
This function find the index of the nearest value to the latitude and longitude values int the l_latitude and
l_longitude lists.
Parameters
----------
latitude: float
longitude: float
l_latitude: list
from collections.abc import Mapping
# Recursive function to apply a func to nested dict
def map_nested_dicts(ob, func):
if isinstance(ob, Mapping):
return {key: map_nested_dicts(value, func) for key, value in ob.items()}
return func(ob)
# Para somar no eixo 1 de três em três
txprec[::3].sum(axis=1)
@beatorizu
beatorizu / apply_format_df_columns.py
Created May 9, 2018 18:05
Aplicando formatos diferentes para cada coluna no DataFrame
# Aplicando formatos diferentes para cada coluna no DataFrame
df = DataFrame({'a':[7.7885], 'b': [1.989878968657576e-10]})
# out
# a b
# 0 7.7885 1.989879e-10
df.loc[:, 'b'] = df.loc[:, 'b'].map(lambda x: float('%.11f' % x))
df.loc[:, 'a'] = df.loc[:, 'a'].map(lambda x: float('%.2f' % x))
# out
@beatorizu
beatorizu / operacoes-eixo-intervalo.py
Last active June 10, 2018 21:27
Aplicar função de acordo com o eixo e cortes por intervalo
import numpy as np
data = np.random.rand(7, 3, 2)
op_dict = {'sum': np.sum, 'mean': np.mean, 'max': np.max, 'min': np.min}
def apply_function(func, data, step, axis=0, slice_=slice(None)):
sections = np.arange(step, data.shape[axis], step)
return np.array([func(d[slice_], axis=axis) for d in np.split(data, sections, axis=axis)])