2. Logistics
• All exercises are shown in repl
• Please paste your repl link for this session in the google sheet
• Be prepared to share your screen
• A repl link with questions to all exercises we will do today in the
class will be provided
3. Course Curriculum
Session Number What is covered
1 Python basics – recap
2 pandas Dataframes and Kaggle dataset
3 Dataset Manipulation - 1
4 REST API and Github
5 Visualization of AI Metrics
6 Visualization of data - 1
7 Visualization of data - 2
8 Final Projects
4. Where will we build
an App?
• An online tool: repl
• Link: https://repl.it/~
• Create a personal account
5. Launch a python program
Click on the blue button on top right corner that says + new repl
8. Operators in python
Operator Syntax Description
Sum + Adds two numbers (or) strings
Subtraction - Only numbers
Product * Product of numbers, repetition of strings
Division / Division between numbers
Modulo % Remainder of division between two
numbers
Power ** Power of one number over another
9. Conditionals
• The if statement
Conditional Description
== Equal
!= Not Equal
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
10. Loops
• The for loop is of the following form.
• The range indicates the number of times a statement will be implemented.
• There is a colon value to indicate the start of for loop.
• The code below is executed many times. The number of times it gets executed
depends on the values specified in range.
• Note that the code below the for statement is indented.
11. Write to a file
• Open a new file if it does not exist
• Write to the file
• Close the file
12. Append to a file
• Open a new file if it does not exist
• Write to the file
• Close the file
13. Lists in python
• A list holds ordered collection of items.
• And item can be a string or a number
14. Dictionaries - Recap
• A dictionary consists of two things (a) keys (b) values
• Use strings to represent keys
• Values can be anything
15. Dictionaries - Recap
• Print a value in a dictionary
• Delete a value in a dictionary
• Print all keys of a dictionary
• Add values to a dictionary
16. Functions can accept and return multiple
values
• How would you call this function?
17. Measuring Run Time of Code
import time
start_time = time.time()
//
print(“Hello”)
//
seconds = time.time() - start_time
print('Time Taken:', time.strftime("%H:%M:%S", time.gmtime(seconds)))
# Output: Time Taken: 00:00:08
● Main() is the function that contains the code to be executed
● We use the time library to ease with measuring run time, various
time zones, and more
27. Exercise
Programming exercise 1:
a) Ask the user to input an integer N. Create a list with the length N, containing
random numbers between 0 and N*2. Make sure that there are no duplicates
in the list created.
b) Create dictionary N keys, where the keys are the values in the list generated
in the previous step. Values are random numbers between 0 and 10.
c) Create a list that contains the values of the dictionary created in the previous
step as its entries.
36. Interpreting CSV Data - Properties
• len() - Returns the total amount of rows
• shape() - Returns an object which contains the total number of rows and
columns
• head(n) - Retrieves the top n (Integer) rows
• info() - Displays all columns and their data types
• dtypes() - Retrieves the column title and its respective data type
• Columns() – Retrieves the column names
39. Sorting CSV Files - Methods
• Multiple different methods to sort columns and values
• sort_values() - sorting the DataFrame by one or more columns
• sort_index() - sorting the DataFrame by the row index
import pandas
nbaDataFrame = pd.read_csv("NBA_CSV_DATA.csv")
nbaDataFrame.sort_values(parameters)
nbaDataFrame.sort_index(parameters)
40. Exploring CSV File Data - Value
• Sorting columns by given player weight (decreasing to increasing)
import pandas
nbaDataFrame = pd.read_csv("NBA_CSV_DATA.csv")
sortedDataFrame = nbaDataFrame.sort_values('Weight',
ascending=True)
print sortedDataFrame[['Weight', 'Name']]
41. Exploring CSV File Data Output
Note* : Values are
sorted by row
index when values
are equal for
given sorting
factor.