Skip to content

Instantly share code, notes, and snippets.

View harpiechoise's full-sized avatar
🎯
Focusing

Jaime Crispi harpiechoise

🎯
Focusing
  • Santiago, Chile
View GitHub Profile
from fastapi import FastAPI, Request
from pydantic import BaseModel, Field
class Result(BaseModel):
result: int = Field(title="Result",
description="The result of an arithmetic operation.")
app = FastAPI(
title="Arithmetic API",
pub trait Summary {
fn sumarize(&self) -> String {
format!("(Read more from {}...)", self.sumarize_author())
}
fn sumarize_author(&self) -> String;
}
pub trait User {
fn printUser(&self) -> ();
}
# La función que se llama a si misma
def contar(n, i=0):
print(f"i: {i}")
if i >= n:
return
return contar(n, i + 1)
# acc
# 0 + 0, i = 0, n = 4 -> suma(4, 0, 1)
# 0 + 1, i = 1, n = 4 -> suma(4, 1, 2)
# 1 + 2, i = 2, n = 4 -> suma(4, 3, 3)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import pandas as pd
import numpy as np
# Series
s = pd.Series(['A', 'B', 'C', 'Casa', 'Vaca', np.nan, 'CABA', 'perro', 'gato'])
# Llevamos las cadenas a minusculas
s.str.lower()
# 0 a
# 1 b
# 2 c
# 3 casa
import pandas as pd
import numpy as np
# 24 Filas
data = {'A': 'uno uno dos tres'.split(' ') * 6,
'B': 'A B C'.split(' ') * 8,
'C': 'Hola adios Como Estas Adios Estas'.split(' ') * 4,
'D': np.random.randint(0, 10, 24),
'E': np.random.randn(24),
'F': pd.date_range("10/11/2011", periods=24)}
import pandas as pd
import numpy as np
# Crear un multi index desde tuplas
indices = [('Santiago', 2000), ('Santiago', 2010),
('California', 2000), ('California', 2010),
('New York', 2000), ('New York', 2010)]
m_indice = pd.MultiIndex.from_tuples(indices)
df = pd.DataFrame([33871648, 37253956, 18976457, 19378102, 20851820, 25145561],
columns=['Poblacion'], index=m_indice)
print(df)
import pandas as pd
# Concatenacion
a = pd.DataFrame({'Numero': [60, 30],
'Animal': ['Panda', 'Leon']})
b = pd.DataFrame({'Peso': [600, 120],
'Patas': [4, 4]})
# Concatenar en filas
import numpy as np
import pandas as pd # Importamos pandas bajo el pseudonimo
# Rango de fechas 8 dias
fechas = pd.date_range('27/2/2019', periods=8)
# Creo un dataframe
df = pd.DataFrame(np.random.random((8, 4)), index=fechas,
columns=['A', 'B', 'C', 'D'])
# Extraigo una Serie del dataframe