Tableaux

Introduction à Python pour la finance

Adina Howe

Instructor

Installation des packages

pip3 install package_name_here
pip3 install numpy
Introduction à Python pour la finance

Importation des packages

import numpy
Introduction à Python pour la finance

NumPy et les tableaux

import numpy

my_array = numpy.array([0, 1, 2, 3, 4])
print(my_array)
[0, 1, 2, 3, 4]
print(type(my_array))
<class 'numpy.ndarray'>
Introduction à Python pour la finance

Utilisation d'un alias

import package_name
package_name.function_name(...)
import numpy as np
my_array = np.array([0, 1, 2, 3, 4])
print(my_array)
[0, 1, 2, 3, 4]
Introduction à Python pour la finance

Pourquoi utiliser un tableau pour l'analyse financière ?

  • Les tableaux permettent de traiter efficacement de très grands ensembles de données
    • Efficacité en termes de mémoire informatique
    • Calculs et analyses plus rapides que les listes
    • Fonctionnalités variées (nombreuses fonctions dans les packages Python)
Introduction à Python pour la finance

Quelle est la différence ?

Tableaux NumPy
my_array = np.array([3, 'is', True])

print(my_array)
['3' 'is' 'True']
Listes
my_list = [3, 'is', True]

print(my_list)
[3, 'is', True]
Introduction à Python pour la finance

Opérations sur les tableaux

Tableaux
import numpy as np

array_A = np.array([1, 2, 3])
array_B = np.array([4, 5, 6])

print(array_A + array_B)
[5 7 9]
Listes
list_A = [1, 2, 3]
list_B = [4, 5, 6]

print(list_A + list_B)
[1, 2, 3, 4, 5, 6]
Introduction à Python pour la finance

Indexation des tableaux

import numpy as np

months_array = np.array(['Jan', 'Feb', 'March', 'Apr', 'May'])

print(months_array[3])
Apr
print(months_array[2:5])
['March' 'Apr' 'May']
Introduction à Python pour la finance

Découpage de tableaux par étapes

import numpy as np

months_array = np.array(['Jan', 'Feb', 'March', 'Apr', 'May'])
print(months_array[0:5:2])
['Jan' 'March' 'May']
Introduction à Python pour la finance

Passons à la pratique !

Introduction à Python pour la finance

Preparing Video For Download...