Corso Python Base: Parte 2 - ForDataScientist 01

19
LEZIONE 1.. PYTHON BASE PARTE 2: strutture dati di base: liste e dizionari; introduzione numpy e pandas.

Transcript of Corso Python Base: Parte 2 - ForDataScientist 01

Page 1: Corso Python Base: Parte 2  - ForDataScientist 01

LEZIONE 1..PYTHON BASEPARTE 2: strutture dati di base: liste e

dizionari; introduzione numpy e pandas.

Page 2: Corso Python Base: Parte 2  - ForDataScientist 01

Riepilogo lezione precedente

interi, floating point, decimal

ATTRIBUTI

METODIOGGETTO

CLASSE

funzioni built-in

stringhe

ITERABLE

print

len

int floatstr

list set

.replace

.upper

.count

if elif else for .. in .. :

Page 3: Corso Python Base: Parte 2  - ForDataScientist 01

COME ORGANIZ-ZARE I DATI

100 324.3 ‘Italia’ 533 ‘FRA’ ‘Oggi è

una bella giornata’ 54.5 True 57 987

False ‘DEU’ ‘config.py’

Page 4: Corso Python Base: Parte 2  - ForDataScientist 01

CONSIDERIAMO UNA SERIE STORICA MENSILE

maggio 2015 125.6

giugno 2015 128.3

luglio 2015 132.9

agosto 2015 133.1

settembre 2015 135.5

ottobre 2015 135.2

novembre 2015 138.6

Page 5: Corso Python Base: Parte 2  - ForDataScientist 01

[ 125.6, 128.3, 132.9, 133.1, 135.5, 135.2, 138.6

]

DIZIONARIO {’201501’ : 125.6, ‘201506’ : 128.3, ‘201507’ : 132.9, ‘201508’ : 133.1 , ‘201509’ : 135.5, ‘201510’ : 135.2, ‘201511’ : 138.6

}

LISTA

Page 6: Corso Python Base: Parte 2  - ForDataScientist 01

[ 125.6, 128.3, 132.9, 133.1, 135.5, 135.2, 138.6

]

DIZIONARIO {’201501’ : 125.6, ‘201506’ : 128.3, ‘201507’ : 132.9, ‘201508’ : 133.1 , ‘201509’ : 135.5, ‘201510’ : 135.2, ‘201511’ : 138.6

}

LISTA

posizione 0posizione 1posizione 2posizione 3posizione 4posizione 5posizione 6

chiavechiavechiavechiavechiavechiavechiave

Page 7: Corso Python Base: Parte 2  - ForDataScientist 01

Assegnazione

LIS1 = [ 125.6, 128.3,

132.9, 133.1, 135.5,

135.2, 138.6 ]

DIZIONARIO Assegnazione

DIZ1 = {’201501’ : 125.6, ‘201506’ : 128.3, ‘201507’ : 132.9, ‘201508’ : 133.1 , ‘201509’ : 135.5, ‘201510’ : 135.2, ‘201511’ : 138.6

}

LISTA

Page 8: Corso Python Base: Parte 2  - ForDataScientist 01

Estrazione

LIS1 [3]

LIS1 [1:3]

LIS1 [:3]

DIZIONARIO

Estrazione

DIZ1 [‘201508’]

LISTA

Page 9: Corso Python Base: Parte 2  - ForDataScientist 01

LEZIONE 1..www.fordatascientist.org

B00-PyBaseB31-Data-Structures-Builtin

Page 10: Corso Python Base: Parte 2  - ForDataScientist 01

LEZIONE 1..www.fordatascientist.org

B00-PyBaseB32-Data-Structures-Other

Page 11: Corso Python Base: Parte 2  - ForDataScientist 01

[ ]

{ } ( )

Data Built-in Data Modulenumpy

pandas.Array

.Series.max().mean()

.Ndarray.std()

.mean(axis=1)

.DataFrame

.index

.index

.columns.index().count()

.count()

.keys

.sort()

.append()

.remove()

Page 12: Corso Python Base: Parte 2  - ForDataScientist 01

LEZIONE 1..www.fordatascientist.org

B00-PyBaseB36-Slicing-Iterable.ipynb

Page 13: Corso Python Base: Parte 2  - ForDataScientist 01

[ ]ESTRATTOREtupla lista Array

Ndarray

SeriesDataFrame

iloc()

Page 14: Corso Python Base: Parte 2  - ForDataScientist 01

A cosa servono le tuple

A= { (‘FRA’,’DEU’,’2015’): 765, (‘FRA’,’ITA’,’2015’): 234, (‘FRA’,’USA’,’2015’): 122, (‘DEU’,’FRA’,’2016’): 975, (‘DEU’,’ITA’,’2016’): 744, (‘DEU’,’USA’,’2016’): 865 }

A= {‘FRA’:{’DEU’:{’2015’: 765}, ’ITA’:{’2015’: 234}, ’USA’:{’2015’: 122} }, ‘DEU’:{’FRA’:{’2016’: 975}, ’ITA’:{’2016’: 744}, ‘USA’:{‘2016’: 865} } }

Nel 2015, la Francia ha esportato verso la Germania 875 milioni di euro; verso l’Italia 234 mln di euro; verso gli Stati Uniti 122 mln di euro;Nel 2016, la Germania ha esportato verso la Francia 975 milioni di euro; verso l’Italia 744; verso gli Stati Uniti 865

A['FRA']['ITA']['2015'] A [ ('FRA','ITA','2015') ]

COSTRUZIONE

ESTRAZIONE

Page 15: Corso Python Base: Parte 2  - ForDataScientist 01

LEZIONE 1..www.fordatascientist.org

B00-PyBaseB53-Custom-Function

Page 16: Corso Python Base: Parte 2  - ForDataScientist 01

def returnparametri

argomenti posizionali *listargomenti di parola chiave **dict

Page 17: Corso Python Base: Parte 2  - ForDataScientist 01

LEZIONE 1..www.fordatascientist.org

B00-PyBaseB71-DateTime

Page 18: Corso Python Base: Parte 2  - ForDataScientist 01

datetime.datetimepandas.Timestamp

istanti temporali

.is_year_end

pandas.Period .freq .period_range

periodi

Page 19: Corso Python Base: Parte 2  - ForDataScientist 01

CONTATTI TELEFONO

051 22 35 20

EMAIL [email protected]