SlideShare a Scribd company logo
Python with AI – 2
Session 1
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
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
Where will we build
an App?
• An online tool: repl
• Link: https://repl.it/~
• Create a personal account
Launch a python program
Click on the blue button on top right corner that says + new repl
Create the first program
Click here
Ask for user input
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
Conditionals
• The if statement
Conditional Description
== Equal
!= Not Equal
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
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.
Write to a file
• Open a new file if it does not exist
• Write to the file
• Close the file
Append to a file
• Open a new file if it does not exist
• Write to the file
• Close the file
Lists in python
• A list holds ordered collection of items.
• And item can be a string or a number
Dictionaries - Recap
• A dictionary consists of two things (a) keys (b) values
• Use strings to represent keys
• Values can be anything
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
Functions can accept and return multiple
values
• How would you call this function?
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
Modules in python
• Use multiple functions written by others
Modules in python
• Use multiple functions written by others
• Popular packages: numpy, pandas
• How do you tell python to use these packages?
Modules in python
• Use multiple functions written by others
• Popular packages: numpy, pandas
• How do you tell python to use these packages?
Numpy package - arrays
• Example of an array
Numpy package - arrays
• Example of a 2D array
Can all lists be converted to numpy arrays?
Why should I use a numpy array?
• Arrays are more convenient – How?
Create random numbers
Create random numbers
• Generate random integers
• Generate random numbers
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.
Modules in python
• Use multiple functions written by others
Modules in python
• Use multiple functions written by others
• Popular packages: numpy, pandas
• How do you tell python to use these packages?
Pandas - Dataframe
• Pandas is useful and important for reading CSV files, the datasets
used for training models
Pandas - Dataframe
• Pandas is useful and important for reading CSV files, the datasets
used for training models
Pandas - Dataframe
• Pandas is useful and important for reading CSV files, the datasets
used for training models
Pandas - Dataframe
• Concept of index in a dataframe
Index
Pandas - Dataframe
• Types of columns in dataframes
Pandas - Dataframe
• Access elements of a dataframe
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
Pandas- Methods
• Dropping columns from a dataframe
Pandas- Methods
• Creating a dataframe from scratch
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)
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']]
Exploring CSV File Data Output
Note* : Values are
sorted by row
index when values
are equal for
given sorting
factor.
http://aiclub.world

More Related Content

What's hot (19)

PPTX
Python with data Sciences
Krishna Mohan Mishra
 
PDF
The Scheme Language -- Using it on the iPhone
James Long
 
PDF
Hash tables and hash maps in python | Edureka
Edureka!
 
ODP
Introduction to Programming in LISP
Knoldus Inc.
 
PPTX
Jake Mannix, Lead Data Engineer, Lucidworks at MLconf SEA - 5/20/16
MLconf
 
PDF
Mathias Brandewinder, Software Engineer & Data Scientist, Clear Lines Consult...
MLconf
 
PPTX
Dictionary based Annotation at Scale with Spark, SolrTextTagger and OpenNLP
Sujit Pal
 
PDF
Introduction to r
Alberto Labarga
 
PDF
Functional Programming #FTW
Adriano Bonat
 
PPTX
Coding and Cookies: R basics
C. Tobin Magle
 
PPTX
Scheme language
JITENDRA LENKA
 
PPTX
Basic lisp
Arvind sahu
 
PPTX
Lisp
sonukumar142
 
PPTX
Scheme Programming Language
Reham AlBlehid
 
PPT
INTRODUCTION TO LISP
Nilt1234
 
PPTX
Basic data analysis using R.
C. Tobin Magle
 
PDF
Pytorch Ecosystem Day: The 珞 Ecosystem
Lysandre Debut
 
PPTX
Python programming
sirikeshava
 
PDF
(Kpi summer school 2015) theano tutorial part1
Serhii Havrylov
 
Python with data Sciences
Krishna Mohan Mishra
 
The Scheme Language -- Using it on the iPhone
James Long
 
Hash tables and hash maps in python | Edureka
Edureka!
 
Introduction to Programming in LISP
Knoldus Inc.
 
Jake Mannix, Lead Data Engineer, Lucidworks at MLconf SEA - 5/20/16
MLconf
 
Mathias Brandewinder, Software Engineer & Data Scientist, Clear Lines Consult...
MLconf
 
Dictionary based Annotation at Scale with Spark, SolrTextTagger and OpenNLP
Sujit Pal
 
Introduction to r
Alberto Labarga
 
Functional Programming #FTW
Adriano Bonat
 
Coding and Cookies: R basics
C. Tobin Magle
 
Scheme language
JITENDRA LENKA
 
Basic lisp
Arvind sahu
 
Scheme Programming Language
Reham AlBlehid
 
INTRODUCTION TO LISP
Nilt1234
 
Basic data analysis using R.
C. Tobin Magle
 
Pytorch Ecosystem Day: The 珞 Ecosystem
Lysandre Debut
 
Python programming
sirikeshava
 
(Kpi summer school 2015) theano tutorial part1
Serhii Havrylov
 

Similar to Pa2 session 1 (20)

PPT
Python
Chetan Khanzode
 
PPTX
Pa1 session 5
aiclub_slides
 
PPTX
Python Tutorial Part 1
Haitham El-Ghareeb
 
PDF
Python Programming and GIS
John Reiser
 
PPT
Python first day
farkhand
 
PPT
Python first day
MARISSTELLA2
 
PPTX
Introduction to Python Basics for PSSE Integration
FarhanKhan978284
 
PPTX
uw cse correct style and speed autumn 2020
abdellahmoukal
 
PDF
web programming UNIT VIII python by Bhavsingh Maloth
Bhavsingh Maloth
 
PPTX
DATA ANALYSIS AND VISUALISATION using python
ChiragNahata2
 
PPTX
Introduction_to_Python.pptx
RahulChaudhary51756
 
PPTX
Engineering CS 5th Sem Python Module -2.pptx
hardii0991
 
PPTX
Python-Basics.pptx
TamalSengupta8
 
PDF
Introduction to Python_for_machine_learning.pdf
goldenflower34
 
PPTX
Introduction to JcjfjfjfkuutyuyrsdterdfbvAVA.pptx
patilrohini0224
 
PPT
Python ppt
Mohita Pandey
 
PDF
"Automata Basics and Python Applications"
ayeshasiraj34
 
PPTX
Python Demo.pptx
ParveenShaik21
 
PPTX
Python Demo.pptx
ParveenShaik21
 
PPTX
Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python (3).pptx
smartashammari
 
Pa1 session 5
aiclub_slides
 
Python Tutorial Part 1
Haitham El-Ghareeb
 
Python Programming and GIS
John Reiser
 
Python first day
farkhand
 
Python first day
MARISSTELLA2
 
Introduction to Python Basics for PSSE Integration
FarhanKhan978284
 
uw cse correct style and speed autumn 2020
abdellahmoukal
 
web programming UNIT VIII python by Bhavsingh Maloth
Bhavsingh Maloth
 
DATA ANALYSIS AND VISUALISATION using python
ChiragNahata2
 
Introduction_to_Python.pptx
RahulChaudhary51756
 
Engineering CS 5th Sem Python Module -2.pptx
hardii0991
 
Python-Basics.pptx
TamalSengupta8
 
Introduction to Python_for_machine_learning.pdf
goldenflower34
 
Introduction to JcjfjfjfkuutyuyrsdterdfbvAVA.pptx
patilrohini0224
 
Python ppt
Mohita Pandey
 
"Automata Basics and Python Applications"
ayeshasiraj34
 
Python Demo.pptx
ParveenShaik21
 
Python Demo.pptx
ParveenShaik21
 
Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python (3).pptx
smartashammari
 
Ad

More from aiclub_slides (20)

PPTX
Linear regression middleschool
aiclub_slides
 
PPTX
Pa2 project template
aiclub_slides
 
PPTX
Knn intro advanced_middleschool
aiclub_slides
 
PPTX
M1 regression metrics_middleschool
aiclub_slides
 
PPTX
Pa1 json requests
aiclub_slides
 
PPTX
Mnist images
aiclub_slides
 
PPTX
Mnist images
aiclub_slides
 
PPTX
Ai in real life face detection
aiclub_slides
 
PPTX
Cnn
aiclub_slides
 
PPTX
Res net high level intro
aiclub_slides
 
PPTX
Neural networks and flattened images
aiclub_slides
 
PPTX
What is a_neural_network
aiclub_slides
 
PPTX
How neural networks learn part iii
aiclub_slides
 
PPTX
Introduction to deep learning image classification
aiclub_slides
 
PPTX
Accuracy middleschool
aiclub_slides
 
PPTX
Introduction to classification_middleschool
aiclub_slides
 
PPTX
Introduction to the cloud
aiclub_slides
 
PPTX
Basics of data
aiclub_slides
 
PPTX
Ai basics
aiclub_slides
 
PPTX
Ai lifecycle and navigator
aiclub_slides
 
Linear regression middleschool
aiclub_slides
 
Pa2 project template
aiclub_slides
 
Knn intro advanced_middleschool
aiclub_slides
 
M1 regression metrics_middleschool
aiclub_slides
 
Pa1 json requests
aiclub_slides
 
Mnist images
aiclub_slides
 
Mnist images
aiclub_slides
 
Ai in real life face detection
aiclub_slides
 
Res net high level intro
aiclub_slides
 
Neural networks and flattened images
aiclub_slides
 
What is a_neural_network
aiclub_slides
 
How neural networks learn part iii
aiclub_slides
 
Introduction to deep learning image classification
aiclub_slides
 
Accuracy middleschool
aiclub_slides
 
Introduction to classification_middleschool
aiclub_slides
 
Introduction to the cloud
aiclub_slides
 
Basics of data
aiclub_slides
 
Ai basics
aiclub_slides
 
Ai lifecycle and navigator
aiclub_slides
 
Ad

Recently uploaded (20)

PPTX
Rules and Regulations of Madhya Pradesh Library Part-I
SantoshKumarKori2
 
PPTX
Translation_ Definition, Scope & Historical Development.pptx
DhatriParmar
 
PPTX
Basics and rules of probability with real-life uses
ravatkaran694
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PDF
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
PPTX
Electrophysiology_of_Heart. Electrophysiology studies in Cardiovascular syste...
Rajshri Ghogare
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PDF
My Thoughts On Q&A- A Novel By Vikas Swarup
Niharika
 
PPTX
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
PPTX
YSPH VMOC Special Report - Measles Outbreak Southwest US 7-20-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
PPTX
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
PPTX
Virus sequence retrieval from NCBI database
yamunaK13
 
PPTX
Digital Professionalism and Interpersonal Competence
rutvikgediya1
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PPT
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
PPTX
I INCLUDED THIS TOPIC IS INTELLIGENCE DEFINITION, MEANING, INDIVIDUAL DIFFERE...
parmarjuli1412
 
PDF
John Keats introduction and list of his important works
vatsalacpr
 
DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
PPTX
LDP-2 UNIT 4 Presentation for practical.pptx
abhaypanchal2525
 
Rules and Regulations of Madhya Pradesh Library Part-I
SantoshKumarKori2
 
Translation_ Definition, Scope & Historical Development.pptx
DhatriParmar
 
Basics and rules of probability with real-life uses
ravatkaran694
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
Electrophysiology_of_Heart. Electrophysiology studies in Cardiovascular syste...
Rajshri Ghogare
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
My Thoughts On Q&A- A Novel By Vikas Swarup
Niharika
 
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 7-20-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
Virus sequence retrieval from NCBI database
yamunaK13
 
Digital Professionalism and Interpersonal Competence
rutvikgediya1
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
I INCLUDED THIS TOPIC IS INTELLIGENCE DEFINITION, MEANING, INDIVIDUAL DIFFERE...
parmarjuli1412
 
John Keats introduction and list of his important works
vatsalacpr
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
LDP-2 UNIT 4 Presentation for practical.pptx
abhaypanchal2525
 

Pa2 session 1

  • 1. Python with AI – 2 Session 1
  • 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
  • 6. Create the first program Click here
  • 7. Ask for user input
  • 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
  • 18. Modules in python • Use multiple functions written by others
  • 19. Modules in python • Use multiple functions written by others • Popular packages: numpy, pandas • How do you tell python to use these packages?
  • 20. Modules in python • Use multiple functions written by others • Popular packages: numpy, pandas • How do you tell python to use these packages?
  • 21. Numpy package - arrays • Example of an array
  • 22. Numpy package - arrays • Example of a 2D array
  • 23. Can all lists be converted to numpy arrays?
  • 24. Why should I use a numpy array? • Arrays are more convenient – How?
  • 26. Create random numbers • Generate random integers • Generate random numbers
  • 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.
  • 28. Modules in python • Use multiple functions written by others
  • 29. Modules in python • Use multiple functions written by others • Popular packages: numpy, pandas • How do you tell python to use these packages?
  • 30. Pandas - Dataframe • Pandas is useful and important for reading CSV files, the datasets used for training models
  • 31. Pandas - Dataframe • Pandas is useful and important for reading CSV files, the datasets used for training models
  • 32. Pandas - Dataframe • Pandas is useful and important for reading CSV files, the datasets used for training models
  • 33. Pandas - Dataframe • Concept of index in a dataframe Index
  • 34. Pandas - Dataframe • Types of columns in dataframes
  • 35. Pandas - Dataframe • Access elements of a dataframe
  • 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
  • 37. Pandas- Methods • Dropping columns from a dataframe
  • 38. Pandas- Methods • Creating a dataframe from scratch
  • 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.