Pachete

Introducere în Python

Hugo Bowne-Anderson

Data Scientist at DataCamp

Motivație

  • Funcțiile și metodele sunt utile

  • Tot codul în distribuția Python?

    • Bază de cod uriașă: dezorganizată

    • Mult cod neutilizat

    • Probleme de întreținere

Introducere în Python

Pachete

  • Director de scripturi Python

  • Fiecare script = modul

  • Definește funcții, metode, tipuri

  • Mii de pachete disponibile

    • NumPy

    • Matplotlib

    • scikit-learn

Captură de ecran a pachetelor Python

Introducere în Python

Instalarea unui pachet

Introducere în Python

Importarea unui pachet

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])
Introducere în 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)
  • Se folosește NumPy, dar nu este clar
Introducere în 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) # Clearly using NumPy
Introducere în Python

Să exersăm!

Introducere în Python

Preparing Video For Download...