Skip to content

Instantly share code, notes, and snippets.

View Pythalex's full-sized avatar

Pythalex

View GitHub Profile
git remote set-branches --add origin [remote-branch]
git fetch origin [remote-branch]:[local-branch]
def to_ms(t, unit):
"""
@param t the time value
@param unit can be 'ms', 's', 'min', 'h', 'd', 'm', 'y'
namely for mili seconds, seconds, minutes, hours, days, months, years
"""
if unit == 'ms':
return t
elif unit == 's':
pd.set_option('display.max_rows', 500)
pd.set_option('display.max_columns', 500)
pd.set_option('display.width', 1000)
# Deux instances de 0 avec une target de chaque
# Deux instances de 1 avec chacune une target à 0
# Deux instances de 2 avec chacune une target à 1
table = np.array([
[0, 0, 1],
[1, 1, 0],
[2, 1, 1]
])
table_df = pd.DataFrame(data=table[:, 1:], index=table[:, 0], columns=["target_0", "target_1"])
@Pythalex
Pythalex / pivot_table.py
Created September 27, 2019 11:13
Pivoter une table en pandas
# Deux instances de 0 avec une target de chaque
# Deux instances de 1 avec chacune une target à 0
# Deux instances de 2 avec chacune une target à 1
table = np.array([
[0, 0],
[0, 1],
[1, 0],
[1, 0],
[2, 1],
[2, 1]
@Pythalex
Pythalex / Calcul_distrib_feature_cat.py
Created September 27, 2019 11:04
Calculer la distribution d'une feature categorielle
df["nom_feature_categorielle"].value_counts()
# exemple
offers_df["proposal.FINANCIALSCALETYPE"].value_counts()
"""
STD 176486
WEB 69209
OPSPE 31862
DERO 15680
PCOL 23
from PIL import Image
img = Image.open("image.jpg")
new_size = (50,50)
img.resize(size=new_size, resample=Image.BILINEAR)
img.save("image_new.jpg")
import time
for i in range(5):
print("\r{}".format(i), end="")
time.sleep(1)
import re
pattern = re.compile("c")
bool(pattern.match("c")) # True
bool(pattern.match("abcde")) # False
bool(pattern.search("abcde")) # True
import json
import requests # pip install requests
from bravado_core.spec import Spec # pip install bravado_core
# get openapi spec
r = requests.get("https://dofapi2.herokuapp.com/openapi.json")
# check response code
if r.status_code != requests.codes.ok:
print("Error : Website spec giver has responded with error code {}".format(r.status_code))