This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* OBMEP 2015 - 2ª Fase - Data */ | |
function sum_digit(number) { | |
var result = 0; | |
while (number) { | |
result += number % 10; | |
number = Math.floor(number / 10); | |
} | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Clean downloaded files | |
Usage: | |
download_cleaner.py <ftpconfig_dir> | |
Arguments: | |
<ftpconfig_dir> Path to ftpconfig directories | |
Options: | |
-h, --help Show this screen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Para somar no eixo 1 de três em três | |
txprec[::3].sum(axis=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)]) |
OlderNewer