Chinmay Takkar 089 CSE-B
Chinmay Takkar 089 CSE-B
B. Tech
In
Chinmay Takkar
ii
ACKNOWLEDGEMENT
I also extend my gratitude to Dr. Deepali Vermani and Prof. Payal Pahwa who
provided their valuable inputs and precious time in accomplishing our projects even
during the Pandemic without fail
Lastly, I would like to thank the almighty and my parents for their moral support and
my batchmates with whom I shared my day-to-day experience and received lots of
suggestions that improved my quality of work.
iii
COMPANY CERTIFICATE
iv
Training Coordinator Certificate
Date: Coordinator
v
ABSTRACT
Training covers 3 months of learning by the project-based method which means learn
by doing.
vi
TABLE OF CONTENT
Declaration …………………………………………………………………………ii
Acknowledgement………………………………………………………………….iii
Company Certificate………………………………………………………………..iv
Abstract …………………………………………………………………………….vi
Chapter 1: Introduction ……………………………………………………………..1
Bibliography ……………………………………………………………………….35
TABLE OF FIGURES
INTRODUCTION
1.1 PYTHON
Python was conceived in the late 1980s by Guido van Rossum at Centrum Wiskunde
& Informatica (CWI) in the Netherlands as a successor to the ABC language (itself
inspired by SETL), capable of exception handling and interfacing with the Amoeba
operating system. Its implementation began in December 1989. Van Rossum
shouldered sole responsibility for the project, as the lead developer, until 12 July
2018, when he announced his "permanent vacation" from his responsibilities as
Python's Benevolent Dictator For Life, a title the Python community bestowed upon
him to reflect his long-term commitment as the project's chief decision-maker. He now
1
shares his leadership as a member of a five-person steering council. In January 2019,
active Python core developers elected Brett Cannon, Nick Coghlan, Barry Warsaw,
Carol Willing, and Van Rossum to a five-member "Steering Council" to lead the
project. Guido van Rossum has since then withdrawn his nomination for the 2020
Steering council.
Python 2.0 was released on 16 October 2000 with many major new features, including
a cycle-detecting garbage collector and support for Unicode.
Python 3.0 was released on 3 December 2008. It was a major revision of the language
that is not completely backward-compatible.[45] Many of its major features were
backported to Python 2.6.x[46] and 2.7.x version series. Releases of Python 3 include
the 2to3 utility, which automates (at least partially) the translation of Python 2 code to
Python 3.
1.3 Python Syntax compared to other programming languages
Python was designed for readability and has some similarities to the English language
with influence from mathematics.
Python relies on indentation, using whitespace, to define scope; such as the scope of
loops, functions, and classes. Other programming languages often use curly-brackets
for this purpose.
There are many features in Python, some of which are discussed below –
• Free and Open Source: Python language is freely available at the official
websiteSince it is open-source, this means that source code is also available to
the public. So you can download it, use it as well as share it.
2
• Object-Oriented Language: One of the key features of python is Object Oriented
programming. Python supports object-oriented language and concepts of
classes, objects encapsulation, etc.
• Large Standard LibraryPython has a large standard library which provides a rich
set of module and functions so you do not have to write your code for every
single thing. There are many libraries present in python for such as regular
expressions, unit-testing, web browsers, etc.
CHAPTER 2
This Specialization builds on the success of the Python for Everybody course and will
introduce fundamental programming concepts including data structures, networked
application program interfaces, and databases, using the Python programming
language. In the Capstone Project, you’ll use the technologies learned throughout the
Specialization to design and create your applications for data retrieval, processing, and
visualization.
In the capstone, students will build a series of applications to retrieve, process, and
visualize data using Python. The projects will involve all the elements of the
specialization. In the first part of the capstone, students will do some visualizations
to become familiar with the technologies in use and then will pursue their project
to visualize some other data that they have or can find.
CHAPTER 3
1. integer:
Example: 2,3,4,1etc.
2. string:
Any character or series of characters in between single (‘) or double (“) quotes
is considered as a String.
3. float:
Example:2.35,5.67 etc.
>>> type(17)
<class 'int'>
>>> type(3.2)
<class 'float'>
3.2 VARIABLES AND STATEMENT
6
>>> n = 17
>>> pi = 3.1415926535897931
>>> type(message)
<class 'str'>
>>> type(n)
<class 'int'>
>>> type(pi)
<class 'float'>
There may be times when you want to specify a type on to a variable. This can be done
with casting. therefore done using constructor functions:
7
• int() - constructs an integer number from an integer literal, a float literal (by
rounding down to the previous whole number), or a string literal (providing the
string represents a whole number)
• float() - constructs a float number from an integer literal, a float literal or a string
literal (providing the string represents a float or an integer)
• str() - constructs a string from a wide variety of data types, including strings,
integer literals, and float literals
8
CHAPTER 4
OPERATOR
• -= Subtract AND Assign: It subtracts the right operand from the left operand and
assigns the result to the left operand
Example => c -= a is equivalent to c = c - a
• *= Multiply AND Assign: It multiplies the right operand with the left operand
and assigns the result to the left operand
Example => c *= a is equivalent to c = c * a
• /= Divide AND Assign: It divides the left operand with the right operand and
assign the result to the left operand
Example =>c /= a is equivalent to c = c / ac /= a is equivalent to c = c / a • %=
Modulus AND Assign: It takes modulus using two operands and assign the result
to the left operand
Example =>c %= a is equivalent to c = c % a
• **= Exponent AND Assign:Performs exponential (power) calculation on
operators and assign value to the left operand
Example =>c **= a is equivalent to c = c ** a
• //= Floor Division AND Assign:It performs floor division on operators and
assign value to the left operand
Example =>c //= a is equivalent to c = c // a
10
11
12
CHAPTER 5
COLLECTION IN PYTHON
5.1 LIST
The list is the most versatile data type available in Python which can be written as a
list of comma-separated values (items) between square brackets. An important thing
about a list is that items in a list need not be of the same type.
Creating a list is as simple as putting different comma-
separated values between square brackets. For example −
list1 = ['physics', 'chemistry', 1997, 2000];
list2 = [1, 2, 3, 4, 5 ];
list3 = ["a", "b", "c", "d"]
Basic List Operations Lists respond to the + and * operators much like strings; they
mean concatenation and repetition here too, except that the result is a new list, not a
string.
5.1.1Built-in List Functions & Methods:
SN Function with Description
1 cmp(list1, list2)
Compares elements of both lists.
2 len(list)
Gives the total length of the list.
3 max(list)
Returns item from the list with max value.
4 min(list)
Returns item from the list with min value.
5 list(seq)
Converts a tuple into a list.
13
14
Accessing Values in Tuples: To access values in the tuple, use the square brackets for
slicing along with the index or indices to obtain the value available at that index. For
example –
tup1 = ('physics', 'chemistry', 1997, 2000);
tup2 = (1, 2, 3, 4, 5, 6, 7 );
print "tup1[0]: ", tup1[0]
print "tup2[1:5]: ", tup2[1:5]
When the code is executed, it produces the following result −
tup1[0]: physics tup2[1:5]: [2, 3, 4, 5]
Updating Tuples: Tuples are immutable which means you
cannot update or change the values of the tuple elements. We
can take portions of existing tuples to create new tuples as
the following example demonstrates −
tup1 = (12, 34.56); tup2 = ('abc', 'xyz'); tup3 = tup1 +
tup2; print tup3 When the above code is executed,
it produces the following result − (12, 34.56,
'abc', 'xyz')
Delete Tuple Elements Removing individual tuple elements is not possible. There is,
of course, nothing wrong with putting together another tuple with the undesired
elements discarded.
To explicitly remove an entire tuple, just use the del statement. For example: tup =
('physics', 'chemistry', 1997, 2000); print tup del tup; print "After deleting tup : " print
tup
3.2.1 Basic Tuples Operations:
SN Function with Description
1 cmp(tuple1, tuple2): Compares elements of both tuples.
2 len(tuple): Gives the total length of the tuple.
3 max(tuple): Returns item from the tuple with max value.
4 min(tuple): Returns item from the tuple with min value.
5 tuple(seq): Converts a list into tuple.
5.3 DICTIONARY
Each key is separated from its value by a colon (:), the items are separated by commas,
and the whole thing is enclosed in curly braces. An empty dictionary without any
items is written with just two curly braces, like this: {}.
15
Keys are unique within a dictionary while values may not be. The values of a
dictionary can be of any type, but the keys must be of an immutable data type such as
strings, numbers, or tuples.
Accessing Values in Dictionary:
To access dictionary elements, you can use the familiar
square brackets along with the key to obtain its value.
Following is a simple example −
dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
print "dict['Name']: ", dict['Name']
print "dict['Age']: ", dict['Age']
Result –
dict['Name']: Zara dict['Age']: 7
Updating Dictionary We can update a dictionary by adding a new entry or a key-value
pair, modifying an existing entry, or deleting an existing entry as shown below in the
simple example
dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
dict['Age'] = 8; # update existing entry dict['School'] = "DPS School"; # Add new
entry print "dict['Age']: ",
dict['Age'] print "dict['School']: ", dict['School']
Result −
dict['Age']: 8 dict['School']: DPS School
Delete Dictionary Elements We can either remove individual dictionary elements or
clear the entire contents of a dictionary. You can also delete entire dictionary in a
single operation.
To explicitly remove an entire dictionary, just use the del statement. Following is a
simple example –
dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
del dict['Name']; # remove entry with key 'Name'
dict.clear(); # remove all entries in dict
del dict ; # delete entire dictionary
print "dict['Age']: ", dict['Age']
print "dict['School']: ", dict['School']
5.3.1 Built-in Dictionary Functions & Methods
SN Function with Description
16
1 cmp(dict1, dict2)
Compares elements of both dict.
2 len(dict)
Gives the total length of the dictionary. This would be equal to the
number of items in the dictionary.
3 str(dict)
Produces a printable string representation of a dictionary
4 type(variable)
Returns the type of the passed variable. If the passed variable is a
dictionary, then it would return a dictionary type.
17
CHAPTER 6
FLOW CONTROL
6.1.1 IF STATEMENT
Syntax:
If test expression:
Statement()
Here, the program evaluates the test expression and will execute statement(s) only if
the test expression is True.
If the test expression is False, the statement(s) is not executed.
In Python, the body of the if the statement is indicated by the indentation. The body
starts with an indentation and the first unindented line marks the end. Python
interprets non-zero values as True. None and 0 are interpreted as False.
Syntax :
if test expression:
statement 1
else:
statement 2
The if … else statement evaluates test expression and will execute the body of if only
when the test condition is True. If the condition is False, the body else is executed.
Indentation is used to separate the blocks.
18
6.1.3 IF…ELIF…ELSE STATEMENT
Syntax:
If test expression:
Body of if
Body of elif
Else:
Body of else
The elif is short for else if. It allows us to check for multiple expressions. If the
condition for if is False, it checks the condition of the next elif block and so on. If all
Only one block among the several if...elif...else blocks is executed according to the
condition.
The if block can have only one else block. But it can have multiple elif blocks.
6.2 ITERATION
The for loop in Python is used to iterate over a sequence (list, tuple, string) or other
iterable objects. Iterating over a sequence is called traversal.
Syntax :
Body of for
Here, Val is the variable that takes the value of the item inside the sequence on each
iteration.
19
Loop continues until we reach the last item in the sequence. The body of for loop is
separated from the rest of the code using indentation.
We can generate a sequence of numbers using the range() function. range(10) will
generate numbers from 0 to 9 (10 numbers). We can also define the start, stop, and
step size as range(start, stop,step_size). step_size defaults to 1 if not provided.
The while loop in Python is used to iterate over a block of code as long as the test
expression (condition) is true. We generally use this loop when we don’t know the
number of times to iterate beforehand.
Syntax :
while test_expression:
Body of while
In the while loop, the test expression is checked first. The body of the loop is entered
only if the test_expression evaluates to True. After one iteration, the test expression is
checked again. This process continues until the test_expression evaluates to False.
In Python, the body of the while loop is determined through indentation. The
body starts with indentation and the first unindented line marks the end. Python
interprets any non-zero value as True. None and 0 are interpreted as False.
20
CHAPTER 7
FUNCTIONS
7.2Calling a Function
Defining a function only gives it a name, specifies the parameters that are to be
included in the function, and structures the blocks of code. Once the basic structure of
a function is finalized, you can execute it by calling it from another function or
directly from the Python prompt.
21
7.3 Scope of Variables
All variables in a program may not be accessible at all locations in that program. This
depends on where you have declared a variable.
The scope of a variable determines the portion of the program where you can access
a particular identifier. There are two basic scopes of variables in Python − 1. Global
variables
2. Local variables
Global vs. Local variables
Variables that are defined inside a function body have a local scope, and those
defined outside have a global scope.
This means that local variables can be accessed only inside the function in which they
are declared, whereas global variables can be accessed throughout the program body
by all functions. When you call a function, the variables declared inside it are
brought into scope.
22
2
CHAPTER 8
FILE HANDLING
We can use python for reading and writing files of different types like txt or binary
etc.
8.1 Files
Files are named locations on disk to store related information. They are used to
permanently store data in non-volatile memory (e.g. hard disk).
Since Random Access Memory (RAM) is volatile (which loses its data when the
computer is turned off), we use files for future use of the data by permanently storing
them.
When we want to read from or write to a file, we need to open it first. When we are
done, it needs to be closed so that the resources that are tied with the file are freed.
1. Open a file
Python has a built-in open() function to open a file. This function returns a file object,
also called a handle, as it is used to read or modify the file accordingly.ng full path We
can specify the mode while opening a file. In mode, we specify whether we want to
read r, write w or append a to the file. We can also specify if we want to open the file
in text mode or binary mode.
The default is reading in text mode. In this mode, we get strings when reading from
the file.
On the other hand, the binary mode returns bytes and this is the mode to be used when
dealing with non-text files like images or executable files.
23
Mode Description
r Opens a file for reading. (default)
w Opens a file for writing. Creates a new file if it does not exist or
truncates the file if it exists
x Opens a file for exclusive creation. If the file already exists, the
operation fails.
a Opens a file for appending at the end of the file without
truncating it. Creates a new file if it does not exist.
t Opens in text mode. (default)
b Opens in binary mode
+ Opens a file for updating (reading and writing)
Unlike other languages, the character does not imply the number 97 until it is encoded using
ASCII (or other equivalent encodings).
Moreover, the default encoding is platform dependent. In windows, it is cp1252 but utf
8 in Linux. So, we must not also rely on the default encoding or else our code will
behave differently in different platforms. Hence, when working with files in text
mode, it is highly recommended to specify the encoding type.
When we are done with performing operations on the file, we need to properly close
the file. Closing a file will free up the resources that were tied with the file. It is done
using the close() method available in Python. Python has a garbage collector to clean
up unreferenced objects but we must not rely on it to close the file.
This method is not entirely safe. If an exception occurs when we are performing some operation
with the file, the code exits without closing the file.
The best way to close a file is by using the statement. This ensures that the file is
closed when the block inside the with statement is exited.
This program will create a new file named test.txt in the current directory if it does
not exist. If it does exist, it is overwritten.
We must include the newline characters ourselves to distinguish the different lines.
We can see that the read() method returns a newline as '\n'. Once the end of the file is
reached, we get an empty string on further reading. We can change our current file
cursor (position) using the seek() method. Similarly, the tell() method returns our
current position (in the number of bytes).
We can read a file line-by-line using a for loop. This is both efficient and fast.
In this program, the lines in the file itself include a newline character \n. So, we use
the end parameter of the print() function to avoid two newlines when printing.
Alternatively, we can use the readline() method to read individual lines of a file. This
method reads a file till the newline, including the newline character.
>>> f.readline()
'This is my first file\n'
>>> f.readline()
'This file\n'
>>> f.readline()
'contains three lines\n'
>>> f.readline()
Lastly, the readlines() method returns a list of remaining lines of the entire file. All
these reading methods return empty values when the end of the file (EOF) is reached.
>>> f.readlines()
['This is my first file\n', 'This file\n', 'contains three lines\n']
There are various methods available with the file object. Some of them have been used
in the above examples.
Here is the complete list of methods in text mode with a brief description:
27
Method Description
close() Closes an opened file. It does not affect if the file is already closed.
Reads at most n characters from the file. Reads till the end of file if
read(n)
it is negative or None.
Reads and returns one line from the file. Reads in at most n bytes if
readline(n=-1)
specified.
Reads and returns a list of lines from the file. Reads in at most n
readlines(n=-1)
bytes/characters if specified.
Changes the file position to offset bytes, about from (start, current,
seek(offset,from=SEEK_SET)
end).
Resizes the file stream to size bytes. If the size is not specified,
truncate(size=None)
resizes to the current location.
Writes the string s to the file and returns the number of characters
write(s)
written.
LIBRARIES
9.1 Numpy
Numeric, the ancestor of NumPy, was developed by Jim Hugunin. Another package
Numarray was also developed, having some additional functionalities. In 2005,
Travis Oliphant created the NumPy package by incorporating the features of
Numarray into the Numeric package. There are many contributors to this open-
source project.
NumPy aims to provide an array object that is up to 50x faster than traditional Python
lists.
The array object in NumPy is called ndarray, it provides a lot of supporting functions
that make working with ndarray very easy.
Arrays are very frequently used in data science, where speed and resources are very
important.
29
9.2 Pandas
Pandas is an open-source Python library providing high-performance data
manipulation and analysis tools using its powerful data structures. The name Pandas
is derived from the word Panel Data – an Econometrics from Multidimensional data.
In 2008, developer Wes McKinney started developing pandas when in need of high
performance, flexible tool for analysis of data.
Before Pandas, Python was majorly used for data munging and preparation. It had
very little contribution to data analysis. Pandas solved this problem. Using Pandas,
we can accomplish five typical steps in the processing and analysis of data,
regardless of the origin of data — load, prepare, manipulate, model, and analyze.
Python with Pandas is used in a wide range of fields including academic and
commercial domains including finance, economics, statistics, analytics, etc.
• Fast and efficient DataFrame object with the default and customized indexing. •
Tools for loading data into in-memory data objects from different file formats. •
Label-based slicing, indexing, and subsetting of large data sets. • Columns from a
9.3 Matplotlib
9.3.1 Introduction
Matplotlib is one of the most popular Python packages used for data visualization. It is a cross-platform
library for making 2D plots from data in arrays. Matplotlib is written in Python and makes use of NumPy, the
numerical mathematics extension of Python. It provides an object-oriented API that helps in embedding plots
in applications using Python GUI toolkits such as PyQt, WxPythonotTkinter. It can be used in Python and
IPython shells, Jupyter notebook, and web application servers also.
Matplotlib has a procedural interface named the Pylab, which is designed to resemble MATLAB, a
proprietary programming language developed by MathWorks. Matplotlib along with NumPy can be
considered as the open-source equivalent of MATLAB.
Matplotlib was originally written by John D. Hunter in 2003. The current stable version is 2.2.0 released in
January 2018.
31
9.4 Seaborn
9.4.1 Introduction
In the world of Analytics, the best way to get insights is by visualizing the data. Data
can be visualized by representing it as plots that are easy to understand, explore, and
grasp. Such data helps in drawing the attention of key elements.
Seaborn helps resolve the two major problems faced by Matplotlib; the problems are
−
As Seaborn compliments and extends Matplotlib, the learning curve is quite gradual.
If you know Matplotlib, you are already halfway through Seaborn.
32
9.5 Plotly
9.5.1 Introduction
Plotly is a Montreal-based technical computing company involved in the
development of data analytics and visualization tools such as Dash and Chart Studio.
It has also developed open-source graphing Application Programming Interface
(API) libraries for Python, R, MATLAB, Javascript, and other computer
programming languages.
• The graphs are stored in JavaScript Object Notation (JSON) data format so that
they can be read using scripts of other programming languages such as R,
Julia, MATLAB, etc.
Developers describe Matplotlib as "A plotting library for the Python programming
language". It is a Python 2D plotting library which produces publication quality
figures in a variety of hardcopy formats and interactive environments across
platforms. It can be used in Python scripts, the Python and IPython shells, the Jupyter
notebook, web application servers, and four graphical user interface toolkits. On the
other hand, Plotly is detailed as "The Web's fastest-growing charting libraries".
Plotly.js is the only open-source JavaScript library for data visualization in the
sciences and engineering. Open-source interfaces to Plotly.js are available for Python,
R, MATLAB, and React.
33
9.6 Tkinter
9.6.1 Introduction
Tkinter is the standard GUI library for Python. Python when combined with Tkinter
provides a fast and easy way to create GUI applications. Tkinter provides a powerful
object-oriented interface to the Tk GUI toolkit.
Creating a GUI application using Tkinter is an easy task. All you need to do is
perform the following steps −
• Enter the main event loop to take action against each event triggered by the
user.
• Colors
• Fonts
• Anchors
• Relief styles
• Bitmaps
• Cursors
34
Bibliography
Links
• https://www.geeksforgeeks.org/
• https://en.wikipedia.org/wiki/Python_(programming_language)
• https://www.google.com
•https://www.tutorialspoint.com/tutorialslibrary.ht
• https://www.python.org/
35