Commit 46aa52c7 authored by George Mount's avatar George Mount
Browse files

clear out cell blocks and files

parent a7fe1175
%% Cell type:markdown id: tags:
# DRILLS
1. Assign the sum of -10 and 2 to `a`.
2. Assign the absolute value of `a` to `b`.
3. Assign `b` minus 1 as `d`.
4. Print the result of `d`. What is the value? What type is this variable?
%% Cell type:code id: tags:
``` python
a = -10 + 2
b = abs(a)
d = b - 1
print(d)
print(type(d))
```
%% Output
7
<class 'int'>
%% Cell type:markdown id: tags:
# DRILL
1. Create a list containing the values `North`, `East`, `South` and `West`.
2. What is the result of the below?
```
len(['Monday','Tuesday','Wednesday','Thursday','Friday',['Saturday','Sunday']])
```
%% Cell type:code id: tags:
``` python
directions = ['North','East','South','West']
print(directions)
print(len(['Monday','Tuesday','Wednesday','Thursday','Friday',['Saturday','Sunday']]))
```
%% Output
['North', 'East', 'South', 'West']
6
%% Cell type:markdown id: tags:
# DRILL
1. What do you expect to be the result of the following? Run the code and see how you did.
```
my_week = (['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'])
my_week.sort()
print(my_week)
```
2. Pass the `clear()` method to `my_week` from above. Re-print `my_week`. What happens?
%% Cell type:code id: tags:
``` python
my_week = (['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'])
my_week.sort()
print(my_week)
```
%% Output
['Friday', 'Monday', 'Saturday', 'Sunday', 'Thursday', 'Tuesday', 'Wednesday']
%% Cell type:code id: tags:
``` python
my_week.clear()
print(my_week)
```
%% Output
[]
%% Cell type:markdown id: tags:
## Drill
Practice some more slicing below:
%% Cell type:code id: tags:
``` python
my_list = [7,12,5,10,9]
# Get the first through third elements
print(my_list[0:3])
# Get the third-last to second-last elements
print(my_list[-3:-1])
# Get the second through last elements
print(my_list[1:5])
```
%% Output
[7, 12, 5]
[5, 10]
[12, 5, 10, 9]
%% Cell type:markdown id: tags:
## DRILL
Practice slicing lists below.
These operations will work the same regardless of whether your list contains floats, strings, or other data types.
%% Cell type:code id: tags:
``` python
this_list = ["Slicing","works","on","lists","of","strings","identically"]
# Get the third to final elements
print(this_list[2:])
# Get everything up to the fourth element
print(this_list[:4])
# Get everything starting with the second-last element
print(this_list[-2:])
```
%% Output
['on', 'lists', 'of', 'strings', 'identically']
['Slicing', 'works', 'on', 'lists']
['strings', 'identically']
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Drill
The `factorial()` function from `math` will take the factorial of a number `X`.
Find the factorial of 10 using this function.
%% Cell type:code id: tags:
``` python
import math
math.factorial(10)
```
%% Output
3628800
%% Cell type:markdown id: tags:
# Drill
Install the `seaborn` package.
%% Cell type:code id: tags:
``` python
#!pip install seaborn
```
......
library(tidyverse)
library(readxl)
region_1 <- read_excel("C:/RFiles/sales_report.xlsx", sheet = "region_1")
head(region_1)
region_2 <- read_excel("C:/RFiles/sales_report.xlsx", sheet = "region_2")
head(region_2)
region_3 <- read_excel("C:/RFiles/sales_report.xlsx", sheet = "region_3")
head(region_3)
region_1 <- read_excel("C:/RFiles/sales_report.xlsx", sheet = "region_1")
head(region_1)
region_2 <- read_excel("C:/RFiles/sales_report.xlsx", sheet = "region_2")
head(region_2)
region_3 <- read_excel("C:/RFiles/sales_report.xlsx", sheet = "region_3")
head(region_3)
region_2$category <- str_to_title(region_2$category)
head(region_2)
# Region 3 -- add the region field
# Yes, just like this!
region_3$region <- 3
head(region_3)
sales_report <- bind_rows(region_1, region_2, region_3)
dim(sales_report)
# Did we get everything?
(nrow(region_1) + nrow(region_2) + nrow(region_3)) == nrow(sales_report)
head(sales_report)
sales_report %>%
group_by(category) %>%
summarise(avg_sales = mean(sales)) %>%
arrange(category)
sales_report %>%
group_by(region) %>%
summarise(total_sales = sum(sales)) %>%
arrange(desc(total_sales))
sales_report %>%
filter(region == 1 | region == 2) %>%
arrange(id) %>%
select(-region)
sales_report %>%
filter(region == 1 | region == 2) %>%
select(-region) %>%
arrange(id)
sales_report %>%
filter(region == 1 | region == 2) %>%
select(-region) %>%
arrange(id)
sales_report %>%
filter(region == 1 | region == 2) %>%
select(-region) %>%
arrange(id)
sales_report %>%
filter(region == 1 | region == 2) %>%
arrange(id) %>%
select(-region)
library(tidyverse)
library(Lahman)
# Players table is stored as Master
data("Master")
data("HallOfFame")
lahman_inner <- inner_join(Master, HallOfFame)
dim(lahman_inner)
dim(lahman_inner)
dim(Master)
dim(HallOfFame)
# Spreadsheet viewing environment
View(lahman_inner)
# What if we just want some fields
inner_join(select(Master, nameFirst, nameLast), HallOfFame)
# What if we just want some fields
inner_join(select(Master, nameFirst, nameLast), HallOfFame)
dim(Master)
dim(HallOfFame)
# What if we just want some fields
inner_join(select(Master, nameFirst, nameLast), HallOfFame)
# Need to keep playerID in the running!
inner_join(select(Master, nameFirst, nameLast, playerID), HallOfFame)
# Compare to left join
lahman_left <- left_join(Master, HallOfFame)
dim(lahman_left)
# Compare to inner join
dim(lahman_inner)
# See the NULLs
View(lahman_left)
library(tidyverse)
library(Lahman)
# Players table is stored as Master
data("Master")
data("HallOfFame")
lahman_inner <- inner_join(Master, HallOfFame)
dim(lahman_inner)
dim(Master)
dim(HallOfFame)
# Spreadsheet viewing environment
View(lahman_inner)
# What if we just want some fields
# this will bring an error --
inner_join(select(Master, nameFirst, nameLast), HallOfFame)
# Need to keep playerID in the running!
inner_join(select(Master, nameFirst, nameLast, playerID), HallOfFame)
# Ordering doesn't matter in inner join
dim(inner_join(HallOfFame, Master))
# Compare to left join
lahman_left <- left_join(Master, HallOfFame)
dim(lahman_left)
# Compare to inner join
dim(lahman_inner)
# See the NULLs
View(lahman_left)
# What about the other way?
lahman_left_other <- left_join(HallOfFame, Master)
dim(lahman_left_other)
# What about the other way?
lahman_left_other <- left_join(HallOfFame, Master)
dim(lahman_left_other)
library(tidyverse)
library(Lahman)
data("Managers")
data("AwardsManagers")
inner_join(Managers, AwardsManagers)
ncol(Managers)
ncol(AwardsManagers)
inner_join <- inner_join(Managers, AwardsManagers)
ncol(Managers)
ncol(AwardsManagers)
dim(inner_join)
names(Managers)
names(AwardsManagers)
# Return the join of records found in both tables.
# Keep all fields except Managers$rank.
inner_join_less_m <- inner_join(select(Managers, -rank), HallOfFame)
dim(inner_join_less_m)
# Return the join of records found in both tables.
# Keep all fields except Managers$rank.
inner_join_less_m <- inner_join(select(Managers, -rank), HallOfFame)
# Return the join of records found in both tables.
# Keep all fields except Managers$rank.
inner_join_less_m <- inner_join(select(Managers, -rank), HallOfFame)
dim(inner_join_less_m)
dim(inner_join)
dim(inner_join)
dim(inner_join_less_m)
head(Managers)
dim(Managers)
dim(select(Managers, -rank))
dim(Managers)
dim(select(Managers, -rank))
dim(Managers)
# Return the join of records found in both tables.
# Keep all fields except Managers$rank.
inner_join_less_m <- inner_join(select(Managers, -rank), AwardsManagers)
# Return the join of records found in both tables.
# Keep all fields except Managers$rank.
inner_join_less_m <- inner_join(select(Managers, -rank), AwardsManagers)
dim(inner_join_less_m)
dim(inner_join)
dim(inner_join_less_m)
# Return the join of records for all found in Managers.
left_join <- left_join(Master, HallOfFame)
dim(left_join)
nrow(Managers)
# Return the join of records for all found in Managers.
left_join <- left_join(Managers, AwardsManagers)
dim(left_join)
nrow(Managers)
# How many more rows does this have than the results of 1?
nrow(left_join(Managers, AwardsManagers)) - nrow(inner_join(Managers, AwardsManagers))
# How many more rows does this have than the results of 1?
nrow(left_join(Managers, AwardsManagers)) - nrow(inner_join(Managers, AwardsManagers))
# How many more rows does this have than the results of 1?
nrow(left_join(Managers, AwardsManagers)) - nrow(inner_join(Managers, AwardsManagers))
# How many more rows does this have than the results of 1?
nrow(left_join) - nrow(inner_join)
# Return the join of records for all found in Managers.
left_join <- left_join(Managers, AwardsManagers)
dim(left_join)
View(left_join)
nrow(AwardsManagers)
nrow(Managers)
nrow(left_join)
nrow(Managers)
nrow(left_join)
library(tidyverse)
library(Lahman)
data("Teams")
teams <- Teams
teams <- filter(teams, yearID >= 2000)
teams <- group_by(teams, teamID)
summarise(teams, mean = mean(W),
min = min(W),
max = max(W))
teams %>%
filter(yearID >= 2000) %>%
group_by(teamID) %>%
summarise(mean = mean(W),
min = min(W),
max = max(W))
teams %>%
filter(yearID >= 2000) %>%
group_by(teamID) %>%
summarise(mean = mean(W),
min = min(W),
max = max(W))
winning <- teams %>%
filter(yearID >= 2000) %>%
group_by(teamID) %>%
summarise(mean = mean(W),
min = min(W),
max = max(W)) %>%
arrange(desc(mean))
head(winning)
[.ShellClassInfo]
InfoTip=This folder is shared online.
IconFile=C:\Program Files\Google\Drive\googledrivesync.exe
IconIndex=16
\ No newline at end of file
region,id,channel,category,sales
1,197,1,Fresh ,30624
1,197,1,Milk ,7209
1,197,1,Grocery ,4897
1,197,1,Frozen ,18711
1,197,1,Deli ,2876
1,197,1,Detergents ,763
1,198,2,Fresh ,2427
1,198,2,Milk ,7097
1,198,2,Grocery ,10391
1,198,2,Frozen ,1127
1,198,2,Deli ,1468
1,198,2,Detergents ,4314
1,199,1,Fresh ,11686
1,199,1,Milk ,2154
1,199,1,Grocery ,6824
1,199,1,Frozen ,3527
1,199,1,Deli ,697
1,199,1,Detergents ,592
1,200,1,Fresh ,9670
1,200,1,Milk ,2280
1,200,1,Grocery ,2112
1,200,1,Frozen ,520
1,200,1,Deli ,347
1,200,1,Detergents ,402
1,201,2,Fresh ,3067
1,201,2,Milk ,13240
1,201,2,Grocery ,23127
1,201,2,Frozen ,3941
1,201,2,Deli ,731
1,201,2,Detergents ,9959
1,202,2,Fresh ,4484
1,202,2,Milk ,14399
1,202,2,Grocery ,24708
1,202,2,Frozen ,3549
1,202,2,Deli ,1681
1,202,2,Detergents ,14235
1,203,1,Fresh ,25203
1,203,1,Milk ,11487
1,203,1,Grocery ,9490
1,203,1,Frozen ,5065
1,203,1,Deli ,6854
1,203,1,Detergents ,284
1,204,1,Fresh ,583
1,204,1,Milk ,685
1,204,1,Grocery ,2216
1,204,1,Frozen ,469
1,204,1,Deli ,18
1,204,1,Detergents ,954
1,205,1,Fresh ,1956
1,205,1,Milk ,891
1,205,1,Grocery ,5226
1,205,1,Frozen ,1383
1,205,1,Deli ,1328
1,205,1,Detergents ,5
1,206,2,Fresh ,1107
1,206,2,Milk ,11711
1,206,2,Grocery ,23596
1,206,2,Frozen ,955
1,206,2,Deli ,710
1,206,2,Detergents ,9265
1,207,1,Fresh ,6373
1,207,1,Milk ,780
1,207,1,Grocery ,950
1,207,1,Frozen ,878
1,207,1,Deli ,285
1,207,1,Detergents ,288
1,208,2,Fresh ,2541
1,208,2,Milk ,4737
1,208,2,Grocery ,6089
1,208,2,Frozen ,2946
1,208,2,Deli ,120
1,208,2,Detergents ,5316
1,209,1,Fresh ,1537
1,209,1,Milk ,3748
1,209,1,Grocery ,5838
1,209,1,Frozen ,1859
1,209,1,Deli ,806
1,209,1,Detergents ,3381
1,210,2,Fresh ,5550
1,210,2,Milk ,12729
1,210,2,Grocery ,16767
1,210,2,Frozen ,864
1,210,2,Deli ,797
1,210,2,Detergents ,12420
1,211,1,Fresh ,18567
1,211,1,Milk ,1895
1,211,1,Grocery ,1393
1,211,1,Frozen ,1801
1,211,1,Deli ,2100
1,211,1,Detergents ,244
1,212,2,Fresh ,12119
1,212,2,Milk ,28326
1,212,2,Grocery ,39694
1,212,2,Frozen ,4736
1,212,2,Deli ,2870
1,212,2,Detergents ,19410
1,213,1,Fresh ,7291
1,213,1,Milk ,1012
1,213,1,Grocery ,2062
1,213,1,Frozen ,1291
1,213,1,Deli ,1775
1,213,1,Detergents ,240
1,214,1,Fresh ,3317
1,214,1,Milk ,6602
1,214,1,Grocery ,6861
1,214,1,Frozen ,1329
1,214,1,Deli ,1215
1,214,1,Detergents ,3961
1,215,2,Fresh ,2362
1,215,2,Milk ,6551
1,215,2,Grocery ,11364
1,215,2,Frozen ,913
1,215,2,Deli ,791
1,215,2,Detergents ,5957
1,216,1,Fresh ,2806
1,216,1,Milk ,10765
1,216,1,Grocery ,15538
1,216,1,Frozen ,1374
1,216,1,Deli ,2388
1,216,1,Detergents ,5828
1,217,2,Fresh ,2532
1,217,2,Milk ,16599
1,217,2,Grocery ,36486
1,217,2,Frozen ,179
1,217,2,Deli ,674
1,217,2,Detergents ,13308
1,218,1,Fresh ,18044
1,218,1,Milk ,1475
1,218,1,Grocery ,2046
1,218,1,Frozen ,2532
1,218,1,Deli ,1158
1,218,1,Detergents ,130
1,219,2,Fresh ,18