Skip to content
Snippets Groups Projects
Commit 7e175b12 authored by msyamkumar's avatar msyamkumar
Browse files

Cleaning up

parent 9fe9aae6
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:6a76ef95 tags:
# Iteration Practice
%% Cell type:markdown id:103da70b tags:
## Learning Objectives
- Iterate through a dataset using for idx in range(project.count())
- Compute the frequency of data that meets a certain criteria
- Find the maximum or minimum value of a numeric column in a dataset
- Handle missing numeric values when computing a maximum / minimum
- Use the index of a maximum or minimum to access other information about that data item
- Use break and continue in for loops when processing a dataset
- Trace the output of a nested loop algorithm that prints out a game grid
%% Cell type:code id:28961628 tags:
``` python
import project
```
%% Cell type:code id:c9341253 tags:
``` python
# TODO: inspect the functions inside project module
```
%% Cell type:code id:d1dca7ae tags:
``` python
# TODO: inspect the project module's documentation
```
%% Cell type:markdown id:7fb78f6b tags:
### How many students does the dataset have?
%% Cell type:code id:d67a080f tags:
``` python
```
%% Cell type:markdown id:3c97d494 tags:
### What is the age of the student at index 10?
%% Cell type:code id:bde8dc35 tags:
``` python
id_10_age = project.???
id_10_age
```
%% Cell type:code id:b0f87a2c tags:
``` python
# TODO: inspect return value type of get_age function
print(type(id_10_age))
```
%% Cell type:markdown id:37898141 tags:
### What is the lecture number of the student at index 20?
%% Cell type:code id:ba993090 tags:
``` python
```
%% Cell type:markdown id:60730da8 tags:
### What is the sleep habit of the student at the last index?
%% Cell type:code id:1d92e499 tags:
``` python
project.???(???)
```
%% Cell type:markdown id:af3d9d8c tags:
### How many current lecture (example: LEC001) students are in the dataset?
- use `for` loop to iterate over the dataset:
- `count` function gives you total number of students
- use `range` built-in function to generate sequence of integers from `0` to `count - 1`
- use `get_lecture` to retrieve lecture column value
- use `if` condition, to determine whether current student is part of `LEC001`
- `True` evaluation: increment count
- `False` evaluation: nothing to do
%% Cell type:code id:e024c488 tags:
``` python
```
%% Cell type:markdown id:b9ff6434 tags:
### What is the age of the oldest student in current lecture (example: LEC001)?
- use `for` loop to iterate over the dataset just like last problem
- use `get_age` to retrieve lecture column value
- if: age is '' (empty), move on to next student using `continue`
- make sure to typecast return value to an integer
- use `get_lecture` to retrieve lecture column value
- use `if` condition, to determine whether current student is part of `LEC001`
- use `if` condition to determine whether current student's age is greater than previously known max age
- `True` evaluation: replace previously known max age with current age
- `False` evaluation: nothing to do
%% Cell type:code id:38bd778a tags:
``` python
```
%% Cell type:markdown id:b40a32fb tags:
### What is the age of the youngest student in current lecture (example: LEC001)?
- use similar algorithm as above question
%% Cell type:code id:ea77e0cd tags:
``` python
```
%% Cell type:markdown id:48f1c791 tags:
### What primary major is the youngest student in current lecture (example: LEC001) planning to declare?
- now, we need to find some other detail about the youngest student
- often, you'll have to keep track of ID of the max or min, so that you can retrive other details about that data entry
%% Cell type:code id:a524873b tags:
``` python
```
%% Cell type:markdown id:5294702a tags:
### Considering current lecture students (example: LEC001), what is the age of the first student residing at zip code 53715?
%% Cell type:code id:fada2a40 tags:
``` python
```
%% Cell type:markdown id:68793d99 tags:
## Self-practice
%% Cell type:markdown id:2eeed867 tags:
### How many current lecture (example: LEC001) students are runners?
%% Cell type:markdown id:1ea57e12 tags:
### How many current lecture (example: LEC001) students are procrastinators?
%% Cell type:markdown id:cf0ac7c8 tags:
### How many current lecture (example: LEC001) students own or have owned a pet?
%% Cell type:markdown id:ffd5e10f tags:
### What sleep habit does the youngest student in current lecture (example: LEC001) have?
- try to solve this from scratch, instead of copy-pasting code to find mimimum age
%% Cell type:markdown id:f255b95a tags:
### What sleep habit does the oldest student in current lecture (example: LEC001) have?
- try to solve this from scratch, instead of copy-pasting code to find mimimum age
%% Cell type:markdown id:db60812c tags:
### Considering current lecture students (example: LEC001), is the first student with age 18 a runner?
%% Cell type:code id:d55fa983 tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment