Forfaits

Introduction à Python

Hugo Bowne-Anderson

Data Scientist at DataCamp

Motivation

  • Fonctions et méthodes : très puissantes

  • Tout le code dans la distribution Python ?

    • Code volumineux : fouillis

    • Beaucoup de code inutile pour vous

    • Entretien difficile

Introduction à Python

Forfaits

  • Répertoire de scripts Python

  • Chaque script = module

  • Définit fonctions, méthodes, types

  • Des milliers de forfaits disponibles

    • NumPy

    • Matplotlib

    • scikit-learn

Capture d'écran du 2019-09-08 à 09 h 18 min 56 s.png

Introduction à Python

Installer un forfait

Introduction à Python

Importer un forfait

import numpy

array([1, 2, 3])
NameError: name 'array' is not defined
numpy.array([1, 2, 3])
array([1, 2, 3])
import numpy as np

np.array([1, 2, 3])
array([1, 2, 3])
from numpy import array

array([1, 2, 3])
array([1, 2, 3])
Introduction à Python

from numpy import array

  • my_script.py
from numpy import array

fam = ["liz", 1.73, "emma", 1.68, "mom", 1.71, "dad", 1.89] ...
fam_ext = fam + ["me", 1.79] ...
print(str(len(fam_ext)) + " elements in fam_ext") ...
np_fam = array(fam_ext)
  • Utilise NumPy, mais ce n'est pas très clair
Introduction à Python

import numpy

import numpy as np

fam = ["liz", 1.73, "emma", 1.68, 
    "mom", 1.71, "dad", 1.89]

...

fam_ext = fam + ["me", 1.79] ...
print(str(len(fam_ext)) + " elements in fam_ext") ...
np_fam = np.array(fam_ext) # Utilise clairement NumPy
Introduction à Python

Passons à la pratique !

Introduction à Python

Preparing Video For Download...