Data Wrangling
Week 3
Dr. Ferdin Joe John Joseph
Faculty of Information Technology
Thai – Nichi Institute of Technology, Bangkok
Today’s Lesson
• Dictionaries
• Control Statements
• Demonstration
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
Dictionary
• Peculiar to python
• Used for mapping
• Hash tables and maps set of objects to a key value
• Available as built in
• Ideal for unstructured data
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
Usage
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
Dictionary keys
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
Dictionary values
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
Key value check
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
Add multiple values
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
Dict as objects
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
Dict: Change values
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
Dict: Number of items
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
Dict: Add new values
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
Dict: Remove specific item
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
Dict: Remove last inserted item
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
Dict: Remove item with specified key name
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
Dict: Delete entire dictionary
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
Dict: Emptying dictionary
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
Copy a dictionary to another
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
Copy using dict() function
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
Nested Dictionaries
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
Control Statements
• While loop
• If statement
• For loop
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
While loop: Syntax
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
While Loop: Example
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
If statement: Syntax
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
If statement: Example with error
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
If statement: Example
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
If-else syntax
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
If-else: Example
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
For Loop: Syntax
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
For Loop: Example
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
For Loop: Example
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
For Loop: Example
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
For Loop: Example
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
Mix of control statements
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
Exercise
• Write python code to generate Fibonacci series of length n. Do it in
Google Colab
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
Exercise
• Write python code to calculate factorial of a number n. Do it in
Google Colab
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
User Defined Function: Syntax
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
User Defined Functions
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
User Defined Functions
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
User Defined Functions
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
User Input
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
Exercise
• Write a user defined function to generate Fibonacci series with a
numeric value as input
• Write a user defined function to calculate the area of rectangle with
numeric values as input
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
Lesson for Next Week
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
https://github.com/ferdinjoe/DSA201

Data wrangling week3