Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs220-lecture-material
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
YE MOU
cs220-lecture-material
Commits
7e175b12
Commit
7e175b12
authored
2 years ago
by
msyamkumar
Browse files
Options
Downloads
Patches
Plain Diff
Cleaning up
parent
9fe9aae6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
f22/meena_lec_notes/lec-12/lec_12_Iteration_Practice_lec001_template.ipynb
+0
-326
0 additions, 326 deletions
...es/lec-12/lec_12_Iteration_Practice_lec001_template.ipynb
with
0 additions
and
326 deletions
f22/meena_lec_notes/lec-12/lec_12_Iteration_Practice_lec001_template.ipynb
deleted
100644 → 0
+
0
−
326
View file @
9fe9aae6
{
"cells": [
{
"cell_type": "markdown",
"id": "6a76ef95",
"metadata": {},
"source": [
"# Iteration Practice"
]
},
{
"cell_type": "markdown",
"id": "103da70b",
"metadata": {},
"source": [
"## Learning Objectives\n",
"\n",
"- Iterate through a dataset using for idx in range(project.count())\n",
"- Compute the frequency of data that meets a certain criteria\n",
"- Find the maximum or minimum value of a numeric column in a dataset\n",
" - Handle missing numeric values when computing a maximum / minimum\n",
" - Use the index of a maximum or minimum to access other information about that data item\n",
"- Use break and continue in for loops when processing a dataset\n",
"- Trace the output of a nested loop algorithm that prints out a game grid"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "28961628",
"metadata": {},
"outputs": [],
"source": [
"import project"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c9341253",
"metadata": {},
"outputs": [],
"source": [
"# TODO: inspect the functions inside project module\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d1dca7ae",
"metadata": {},
"outputs": [],
"source": [
"# TODO: inspect the project module's documentation\n"
]
},
{
"cell_type": "markdown",
"id": "7fb78f6b",
"metadata": {},
"source": [
"### How many students does the dataset have?"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d67a080f",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "3c97d494",
"metadata": {},
"source": [
"### What is the age of the student at index 10?"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bde8dc35",
"metadata": {},
"outputs": [],
"source": [
"id_10_age = project.???\n",
"id_10_age"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b0f87a2c",
"metadata": {},
"outputs": [],
"source": [
"# TODO: inspect return value type of get_age function\n",
"print(type(id_10_age))"
]
},
{
"cell_type": "markdown",
"id": "37898141",
"metadata": {},
"source": [
"### What is the lecture number of the student at index 20?"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ba993090",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "60730da8",
"metadata": {},
"source": [
"### What is the sleep habit of the student at the last index?"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1d92e499",
"metadata": {},
"outputs": [],
"source": [
"project.???(???)"
]
},
{
"cell_type": "markdown",
"id": "af3d9d8c",
"metadata": {},
"source": [
"### How many current lecture (example: LEC001) students are in the dataset? \n",
"\n",
"- use `for` loop to iterate over the dataset:\n",
" - `count` function gives you total number of students\n",
" - use `range` built-in function to generate sequence of integers from `0` to `count - 1`\n",
"- use `get_lecture` to retrieve lecture column value\n",
"- use `if` condition, to determine whether current student is part of `LEC001`\n",
" - `True` evaluation: increment count\n",
" - `False` evaluation: nothing to do"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e024c488",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "b9ff6434",
"metadata": {},
"source": [
"### What is the age of the oldest student in current lecture (example: LEC001)?\n",
"\n",
"- use `for` loop to iterate over the dataset just like last problem\n",
"- use `get_age` to retrieve lecture column value\n",
" - if: age is '' (empty), move on to next student using `continue`\n",
" - make sure to typecast return value to an integer\n",
"- use `get_lecture` to retrieve lecture column value\n",
"- use `if` condition, to determine whether current student is part of `LEC001`\n",
" - use `if` condition to determine whether current student's age is greater than previously known max age\n",
" - `True` evaluation: replace previously known max age with current age\n",
" - `False` evaluation: nothing to do"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "38bd778a",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "b40a32fb",
"metadata": {},
"source": [
"### What is the age of the youngest student in current lecture (example: LEC001)?\n",
"- use similar algorithm as above question"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ea77e0cd",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "48f1c791",
"metadata": {},
"source": [
"### What primary major is the youngest student in current lecture (example: LEC001) planning to declare?\n",
"- now, we need to find some other detail about the youngest student\n",
"- 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",
"execution_count": null,
"id": "a524873b",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "5294702a",
"metadata": {},
"source": [
"### Considering current lecture students (example: LEC001), what is the age of the first student residing at zip code 53715?"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fada2a40",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "68793d99",
"metadata": {},
"source": [
"## Self-practice"
]
},
{
"cell_type": "markdown",
"id": "2eeed867",
"metadata": {},
"source": [
"### How many current lecture (example: LEC001) students are runners? "
]
},
{
"cell_type": "markdown",
"id": "1ea57e12",
"metadata": {},
"source": [
"### How many current lecture (example: LEC001) students are procrastinators? "
]
},
{
"cell_type": "markdown",
"id": "cf0ac7c8",
"metadata": {},
"source": [
"### How many current lecture (example: LEC001) students own or have owned a pet?"
]
},
{
"cell_type": "markdown",
"id": "ffd5e10f",
"metadata": {},
"source": [
"### What sleep habit does the youngest student in current lecture (example: LEC001) have?\n",
"- try to solve this from scratch, instead of copy-pasting code to find mimimum age"
]
},
{
"cell_type": "markdown",
"id": "f255b95a",
"metadata": {},
"source": [
"### What sleep habit does the oldest student in current lecture (example: LEC001) have?\n",
"- try to solve this from scratch, instead of copy-pasting code to find mimimum age"
]
},
{
"cell_type": "markdown",
"id": "db60812c",
"metadata": {},
"source": [
"### Considering current lecture students (example: LEC001), is the first student with age 18 a runner?"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d55fa983",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
%% 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
:
3
c97d494
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
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment