Utilisation des tableaux pour les analyses

Introduction à Python pour la finance

Adina Howe

Instructor

Indexation des tableaux

import numpy as np

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

indexing_array = np.array([1, 3, 5])
months_subset = months_array[indexing_array]
print(months_subset)
['Feb' 'Apr' 'Jun']
Introduction à Python pour la finance

Plus d'informations sur l'indexation des tableaux

import numpy as np

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

negative_index = np.array([-1, -2])

print(months_array[negative_index])
['Jun' 'May']
Introduction à Python pour la finance

Tableaux booléens

import numpy as np

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

boolean_array = np.array([True, True, True, False, False, False])

print(months_array[boolean_array])
['Jan' 'Feb' 'Mar']
Introduction à Python pour la finance

Plus d'informations sur les tableaux booléens

prices_array = np.array([238.11, 237.81, 238.91])

# Create a Boolean array boolean_array = (prices_array > 238) print(boolean_array)
[ True False  True]
print(prices_array[boolean_array])
[ 238.11  238.91]
Introduction à Python pour la finance

Passons à la pratique !

Introduction à Python pour la finance

Preparing Video For Download...