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 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 |
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 pandas as pd # Seudonimo de pandas | |
# Tipo de dato Serie | |
# Series | |
a = pd.Series([1, 2, 3]) # Objeto Series | |
print(type(a)) # <class 'pandas.core.series.Series'> | |
print(a) | |
# 0 1 | |
# 1 2 |
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 # Importamos numpy bajo el seudonimo | |
a = np.arange(10) + 50 # Creamos un rango y le sumamos 50 | |
print(a[2]) # Si quiero acceder al tercer elemento | |
print(a[-2]) # Si quiero el penultimo valor de mi Array | |
# 58 | |
# Seleccionar un rango de elementos | |
print(a[2:5]) # Seleccionar desde tercer elemento al sexto elemento |
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 # Importamos numpy con bajo el alias | |
a = np.arange(10) # Creo un rango del 1 al 9 | |
print(a + 10) # [10 11 12 13 14 15 16 17 18 19] | |
a = np.eye(3) # Creo una matriz diagonal de 3x3 | |
b = np.eye(3, k=-1) # Creo una matriz diagonal de 3x3 | |
print(a + b) | |
# [[1. 0. 0.] | |
# [1. 1. 0.] |
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 # Importamos numpy bajo seudonimo | |
# a = np.array(1, 2, 3) # Esto está mal | |
a = np.array([1, 2, 3]) # Mi funcion recibe una lista como parámetro | |
a = np.array([1, 2, 3]) | |
a.dtype # dtype('int64') | |
a.itemsize # 8 | |
a = np.array([1., 2., 3.]) # Le pasaremos valores decimales |
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 # Importamos numpy para usarlo en nuestro codigo | |
import numpy as np # Importamos con un alias | |
a = numpy.array([1, 2, 3]) # Creamos una array de numpy | |
print(a) # [1 2 3] | |
# Bajo el alias | |
a = np.array([1, 2, 3]) # Creamos una array de numpy | |
print(a) # [1 2 3] |
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 # Importamos numpy | |
a = np.arange(25).reshape(5, 5) # Hacemos una matriz de 5 x 5 | |
print(a > 10) | |
# [[False False False False False] | |
# [False False False False False] | |
# [False True True True True] | |
# [ True True True True True] | |
# [ True True True True True]] |
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 # Importamos numpy | |
# Numpy Linspace | |
a = np.linspace(10, 50, 5) | |
# 5 Valores igualmente distribuidos, es decir, sus distancias son iguales | |
print(a) | |
# [10. 20. 30. 40. 50.] | |
print(a.itemsize) # Tamaño en Bytes de cada elemento | |
# 8 |
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 | |
# 2 Útilidades | |
# Principio del Rango de numpy | |
print(np.arange(2, 13)) # [ 2 3 4 5 6 7 8 9 10 11 12] | |
# Pasos del rango | |
print(np.arange(2, 13, 2)) # [ 2 4 6 8 10 12] | |
# Matriz de zeros |
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
# Importamos Numpy | |
import numpy | |
from timeit import timeit # Utilidad para hacer pruebas de rendimiento | |
import numpy as np | |
# Crear una array de numpy | |
numpy.array([1, 2, 3]) # array([1, 2, 3]) | |
# Reduccion de la importacion | |
# Linea: 4 | |
np.array([1, 2, 3]) # array([1, 2, 3]) |