Skip to content

Instantly share code, notes, and snippets.

View generics.rs
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) -> ();
}
View recursion.py
# 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)
View 2 Ejercicios.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View La cosa del colab.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View Textos.py
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
View Tablas pivote.py
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)}
View Multi indice.py
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)
View Merging.py
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
View indices.py
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
View Pandas Datos.py
import pandas as pd # Importamos pandas bajo el seudonimo
# Leer datos en CSV
df = pd.read_csv('iris.csv') # Abrir un CSV con headers
df.head(2) # Primeros 2 valores del dataset
# sepal length in cm sepal width in cm ...
# 0 5.1 3.5
# 1 4.9 3.0
df.tail(2) # Ultimos 5 valores del dataset