Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como PDF o lee en línea desde Scribd
Está en la página 1/ 3
in (29)
out(29)
in (39)
In (31)
Funcién pivot_table()
import pancas
as pd
import nunpy a5 np
mne-nead)
tune = pd.read_esv("Fortune.csv")
pvc) Naar
company ek rakcehangs rovanoe ott yn TMtOOf ctr yatta necro. fumtar ne woman
oan 4 20 saree 138780 2300000 Retain Senommte AR v °
+ Amazon 2 00 4020 229640 s680609 Retin Seale WA ne ~ ~
2 hens 00 058170 946500 1580600 Tacmy Cipoio CA ° °
+ co asrearo izase 500000 MS jimtona MN mo ve v=
near_profits =
Fortune[ "reveni
Fortune[ "Revenue. segnentat ion
Fortunel "Revenve_segnentaton*) .value_counts()
High 202
Name: Revenve_segnentation, dtype: inte
lochs 088 nebotsCPE anal eas on Pont ter
mmean() # colculo el pronedio
‘np-wnere(Fortune["revenue"]
> mean profits,
High",20924.7908m phe) der Naar
In (22): pd.pivot_table(data = fortune,
index = [sector],
columns = ["Revenve_segnentation”],
agefune = ‘size’,
Fill_value = 0) #” ‘size’ indica que se estd contando el numero de ocurrencias (tana)
out (32:
mentation High Low
‘Aerospace &Defense 512
Chemicals 326
Food &Drug stows 54
Motes, Restaurants &Lelsure 226
Modis 325
Retahing 17 60
Tecmology 22 99
Transporation 728
Wwolesalere 9 22
lochs 088 nebotsCPE anal eas on Pont ter20924.7908m phot) der Natio
In (33): # Creor La tobta pivotada
pivot_table = pd.pivot_table(data = fortune,
values = "revenue’,
index = ["sector’, “eity"],
columns = ["Revenue_segnentation”),
aggfunc = ("revenue™: ["sun", 's42e"]},
fill_value = 0)
pivot_table.columns = ['_'
Jein(col).strip() for col in pivot_table.colunns)
pivot_table
sae High szn_Low sum High sum_Low
sector ety
“Aerospace & Defense Bothesda 1 0 woo ab
Cleveana ° 1 op 47280
East Aurora ° 1 00 20520
St Lou ° 2 09 M2
1739 rows » 4 columns
lochs 088 nebotsCPE anal eas on Pont ter