Data manipulatie in Julia
Katerina Zahradova
Instructor
# Bedrijven in verschillende landen
choc_comp_france = filter(chocolates -> chocolates.company_location == "France", chocolates)
choc_comp_brazil = filter(chocolates -> chocolates.company_location == "Brazil", chocolates)
choc_comp_peru = filter(chocolates -> chocolates.company_location == "Peru", chocolates)
choc_comp_belgium = filter(chocolates -> chocolates.company_location == "Belgium", chocolates)
...


# Groeperen op company_location
groupby(chocolates, :company_location)
GroupedDataFrame met 60 groepen op sleutel: company_location
Eerste groep (156 rijen): company_location = "France"
Row company bean_origin ...
String String ...
_______________________________
1 A. Morin Agua Grande ...
...
Laatste groep (4 rijen): company_location = "Ireland"
Row company bean_origin ...
String String ...
_______________________________
1 Wilkie's Organic Amazonas ...
groupby(chocolates, [:company_location, :cocoa])
GroupedDataFrame met 373 groepen op sleutels: company_location, cocoa
Eerste groep (5 rijen): company_location = "France", cocoa = 63.0
Row company bean_origin ...
String String ...
_______________________________
1 A. Morin Agua Grande ...
...
Laatste groep (1 rij): company_location = "Ireland", cocoa = 89.0
Row company bean_origin ...
String String ...
_______________________________
1 Wilkie's Organic Amazonas ...

# Groeperen op land
chocolates_by_country = groupby(chocolates, :company_location)
# Aantal rijen per groep
combine(chocolates_by_country, nrow => :count)
60x2 DataFrame
Row company_location nrow
String31 Int64
______________________________
1 France 156
2 U.S.A. 764
3 Fiji 4
...
# Groeperen op land
chocolates_by_country = groupby(chocolates, :company_location)
# Sorteer op aantal rijen
sort(combine(chocolates_by_country, nrow => :count), :count, rev = true)
60x2 DataFrame
Row company_location nrow
String31 Int64
______________________________
1 U.S.A 764
2 France 156
3 Canada 125
...
# Unieke elementen
unique(chocolates.company_location)
60-element Vector{String31}:
"France"
"U.S.A."
"Fiji"
"Ecuador"
"Mexico"
"Switzerland"
"Netherlands"
...
# Maak een nieuwe DF met alleen unieke rijen
unique(chocolates)
1795×10 DataFrame
Row company bean_origin ...
String String ...
_________________________________
1 A. Morin Agua Grande ...
...
# Unieke bedrijfsrecords
unique(chocolates, :company)
416×10 DataFrame
Row company bean_origin ...
String String ...
_________________________________
1 A. Morin Agua Grande ...
...
# Unieke combinaties van bedrijf EN cacaopercentage
unique(chocolates, [:company, :cocoa])
968×10 DataFrame
Row company bean_origin ...
String String ...
_________________________________
1 A. Morin Agua Grande ...
...
Data manipulatie in Julia