The libraries are loaded in the setup chunk above.
read_excel()# IMPORTANT: Put bikes.xlsx in the SAME folder as this .Rmd file before you Knit.
bikes <- read_excel("bikes.xlsx")
# Quick check that it loaded
bikes %>% glimpse()
## Rows: 97
## Columns: 4
## $ bike.id <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,…
## $ model <chr> "Supersix Evo Black Inc.", "Supersix Evo Hi-Mod Team", "Su…
## $ description <chr> "Road - Elite Road - Carbon", "Road - Elite Road - Carbon"…
## $ price <dbl> 12790, 10660, 7990, 5330, 4260, 3940, 3200, 2660, 2240, 18…
model and price
with price in descending orderimport pandas as pd
# Pull the R tibble `bikes` into Python as a pandas DataFrame
bikes = r.bikes
# Keep only model + price, sort by price descending
bikes_model_price_desc = bikes.loc[:, ["model", "price"]].sort_values(by="price", ascending=False)
bikes_model_price_desc
## model price
## 0 Supersix Evo Black Inc. 12790.0
## 54 Scalpel-Si Black Inc. 12790.0
## 80 Habit Hi-Mod Black Inc. 12250.0
## 65 F-Si Black Inc. 11190.0
## 1 Supersix Evo Hi-Mod Team 10660.0
## .. ... ...
## 92 Trail 5 815.0
## 93 Catalyst 1 705.0
## 94 Catalyst 2 585.0
## 95 Catalyst 3 480.0
## 96 Catalyst 4 415.0
##
## [97 rows x 2 columns]
model and price
where price is greater than the mean pricemean_price = bikes["price"].mean()
bikes_above_mean = bikes.loc[bikes["price"] > mean_price, ["model", "price"]]
mean_price, bikes_above_mean
## (np.float64(3953.762886597938), model price
## 0 Supersix Evo Black Inc. 12790.0
## 1 Supersix Evo Hi-Mod Team 10660.0
## 2 Supersix Evo Hi-Mod Dura Ace 1 7990.0
## 3 Supersix Evo Hi-Mod Dura Ace 2 5330.0
## 4 Supersix Evo Hi-Mod Utegra 4260.0
## 10 CAAD12 Black Inc 5860.0
## 11 CAAD12 Disc Dura Ace 4260.0
## 21 Synapse Hi-Mod Disc Black Inc. 9590.0
## 22 Synapse Hi-Mod Disc Red 7460.0
## 23 Synapse Hi-Mod Dura Ace 5860.0
## 24 Synapse Hi-Mod Disc Ultegra 5330.0
## 25 Synapse Carbon Disc Ultegra D12 4800.0
## 37 Slice Hi-Mod Black Inc. 7000.0
## 38 Slice Hi-Mod Dura Ace D12 4500.0
## 46 Jekyll Carbon 1 7990.0
## 47 Jekyll Carbon 2 6070.0
## 50 Trigger Carbon 1 8200.0
## 51 Trigger Carbon 2 5970.0
## 54 Scalpel-Si Black Inc. 12790.0
## 55 Scalpel-Si Race 9060.0
## 56 Scalpel-Si Hi-Mod 1 7460.0
## 57 Scalpel-Si Carbon 2 6390.0
## 58 Scalpel-Si Carbon 3 5330.0
## 59 Scalpel-Si Carbon 4 4260.0
## 61 Scalpel 29 Carbon Race 6390.0
## 62 Scalpel 29 Carbon 2 5330.0
## 63 Scalpel 29 Carbon 3 4260.0
## 65 F-Si Black Inc. 11190.0
## 66 F-Si Hi-Mod Team 9060.0
## 67 F-Si Hi-Mod 1 6390.0
## 68 F-Si Carbon 2 4800.0
## 80 Habit Hi-Mod Black Inc. 12250.0
## 81 Habit Carbon 1 7460.0
## 82 Habit Carbon 2 5330.0
## 83 Habit Carbon SE 4480.0)