Lecture 01
Lecture 01
1
Part I: Contents of Python programing
• Introduction to Python
• Python Operators
• Function
• Modules
2
Introduction to Python
Python is a high-level, interpreted, interactive and object-
oriented scripting language.
Print(“Hello World”)
Note:
Python Identifiers: A Python identifier is a name used to identify a variable,
function, class, module or other object.
Reserved Words: These are reserved words and you cannot use them as
constant or variable or any other identifier names.
Lines and Indentation: In python, blocks of code for class, function definitions
or flow control are denoted by line indentation, which is rigidly enforced.
Quotation in Python: Python accepts single ('), double (") and triple (''' or """)
quotes to denote string literals, as long as the same type of quote starts and
ends the string.
• Multi-line Comments(""“)
Python Variables, data types
Variables are used for holding data values so that they can be
utilized in various computations in a program.
Example 2:
age = input("How old are you? ")
print(“age” )
Print(age)
Example 3:
age = int(input("How old are you? "))
print(“age” )
Print(age)
Operators in Python
Operator in python are used to perform operations between
variables
Result
10
Types of operator in Python
1.Arithmetic Operators
addition(+)
subtraction(-)
Multiplication(*)
Division(/)
modules(%)
Exponentiation(**)
11
Cont…
2.Assignment operator
Operator Example
= x=10
12
Cont…
3. Comparison operator
3.Greater than(>)
5 .Less than(<)
15
Cont…
6. Membership Operator
Example. List1=[1,2,3,5,6)
list2=[1,2,3]
5.Left Shift(<<)- shift left by pushing in zeros from the right and
let the leftmost bits fell off.
18
Python Collections
There are four collection data types in the Python programming
language:
print(mylist[1])
print(mylist[-1])
print(mylist[1:3])
Access Items: You access the list items by referring to the index
number:
Example: mylist=("apple", "banana", "cherry", "orange“)
print(mylist)
print(mylist[1])
print(mylist[-1])
print(mylist[1:3])
print(mytuple[1])
print(mytuple[-1])
print(mytuple[1:3])
Print(mydictionary)
• But you can loop through the set items using a for loop, or ask if a
specified value is present in a set, by using the in keyword.
myset=("apple", "banana", "cherry", "orange“)
print(mytuple)
Example,
a=20
b=33
if b>a:
print("b is greater than a")
elif a==b:
print("a and b are equal")
else:
print("a is greater than b")
Cont…
and
The and keyword is a logical operator, and is used to combine
conditional statements:
a=200
b=33
c=500
if a > b and c > a:
print("Both conditions are True")
cont…
Or
The or keyword is a logical operator, and is used to combine
conditional statements:
a=200
b=33
c=500
if a>b or a>c:
print("At least one of the conditions is True")
cont…
Nested If
You can have if statements inside if statements, this is
called nested if statements.
Example
x=41
if x>10:
print("Above ten,")
if x>20:
print("and also above 20!")
else:
print("but not above 20.")
Loops
A loop statement allows us to execute a statement or group of
statements multiple times.
– while loops
– for loops
The while Loop
With the while loop we can execute a set of statements as long
as a condition is true.
while expression:
statement(s)
i=1
while i<6:
print(i)
i+=1
The break Statement
• With the break statement we can stop the loop even if the
while condition is true:
The "inner loop" will be executed one time for each iteration of
the "outer loop":
def my_function():
print("Hello from a function")
Calling a Function
def my_function():
print("Hello from a function")
def my_function() 44
Cont…
Function Arguments
Example
def my_function(fname):
print(fname + " is CS program student")
my_function(“Abebe")
my_function(“Hana")
my_function(“Azeb") 45
Cont…
Return values
Example
def my_function(x): Output
return 5*x 15
25
Print(my_function(3)) 50
Print(my_function(5))
Print(my_function(10))
46
Scope of Variables
In Python, variables are the containers for storing data
values.
1. Global variables
X=3
Y=1
Def function1():
print(x+y)
person1 = {
"name": "John",
"age": 36,
"country": "Norway"
}
person1 = {
"name": "John",
"age": 36,
"country": "Norway"
}
55
An Overview of Data Science
Data science means extraction of knowledge from large
volumes of data that are structured or unstructured.
56
Cont.…
Today, data professionals understand that they must advance
the traditional skills of analyzing large amounts of data, data
mining, and programming skills.
Data scientists must master the full field of the data science
life cycle and keep a level of flexibility and understanding to
maximize returns at each phase of the process..
57
Cont…
• Statistics and
• Linear algebra,
• Programming ,
• Data warehousing,
58
Typical jobs for data scientists
Collects large amounts of data and transforming it into more
usable format.
60
Who are data scientists?
Computer science-20%
Engineering-9%
Others-9%
61
What are data and information?
Data :-can be defined as a representation of facts, concepts,
or instructions in a formalized manner, which should be
suitable for communication, interpretation, or processing,
by human or electronic machines.
62
Cont.…
Information:- is the processed data on which decisions and
actions are based.
63
Data Processing Cycle
Data processing is the re-structuring or re-ordering of data
by people or machines to increase their usefulness and add
values for a particular purpose.
• Input,
• Processing, and
• Output.
These three steps constitute the data processing cycle.
64
Cont.…
Input - in this step, data is prepared in some convenient form for
processing.
66
Data types and their representation
Data types are described from diverse views in computer
science and computer programming,
67
Data types from Computer programming perspective
Integers(int)- is used to store numbers, mathematically known
as integers. Example 1 and 3645
69
Structured Data
Structured data is data that follows to a pre-defined data
model and is therefore direct to analyze.
70
Semi-structured Data
Data between structured and unstructured.
71
Unstructured Data
Its information that either not organized in a pre-defined
manner.
72
Metadata – Data about Data
The last category of data type is metadata.
73
Data science life cycle
1. Business Requirements:
Understanding the problems of business.
74
2. Data collection
Process of gathering data before it is put in data warehouse
or storage on which data analysis can be carried out.
75
3. Data cleaning
sometimes unnecessary data is collected such that only
increases complexity of the problem
Challenging is integration.
Data cleaning:-
• Corrupted data
• misspelled value
• inconsistent data
76
4. Data exploration and analysis
Making raw data open to use in decision-making as well as
domain-specific usage.
77
5. Data modeling
Create a model that predicts the target most accurately.
78
6. Deployment and optimization
Last stage is deployed in users and feedback is collected and
maintained.
79
Data science process life cycle
80
Needs of data science
Solves business problems
81
Seminar on Python Libraries for Data Science