Python For Data Science
Python For Data Science
me/Notes_CAFinal
Learning Objectives
UNDERSTANDING THE FUNDAMENTALS OF PYTHON AND ITS VERSATILITY.
PROPERTIES OF LIST AND TUPLE. VARIOUS OPERATIONS PERFORMED ON BOTH LIST AND TUPLE.
#Example of a Script
import yagmail
user = [Link](user=‘testmail@[Link]',password='zpsgowuwqlansmfv’)
[Link](to ='accounts@[Link]', subject ='Sales_Reports',contents ='This is test mail for python automation',
attachments = '[Link]')
Chat GPT Prompt
Explain how the
From above piece of code its easy to guess in Line no 1 yagmail laibrary is imported code <Paste code
here> works in
Python..
In Line 2 the from mail id ‘testmail@[Link]’, and password is set as 'zpsgowuwqlansmfv’
Line 3 send the email to 'accounts@[Link]’, with subject Sales report and with body of email and attachment of
file named [Link]
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Go to [Link]
Click download the relevant files based on the OS and version
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
- IDLE - [Link]
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Variables: Variables are containers for storing data values. Python has no command for
declaring a variable. A variable is created the moment you first assign a value to it.
Example: x = 5
y = "John"
print(x)
print(y)
Refer more for Variables naming in -
[Link]
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Comparison operators
Logical operators
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Comparison operators
Logical operators
Identity operators
Membership operators
Bitwise operators
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Exercise
Arithmetic operators - (INT20)
Comparison operators - (INT20)
Logical operators - (INT20)
Membership operators - (INT20)
The common convention is to alias NumPy as `np`.
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Code Result
\' Single Quote
\\ Backslash
\nas `np`.
The common convention is to alias NumPy New Line
\r Carriage Return
\t Tab
\b Backspace
\f Form Feed
\ooo Octal value
\xhh Hex value
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Introduction - Numeric
Numeric: The numeric data type in Python represents the data that has a numeric
value. A numeric value can be an integer, a floating number, or even a complex
number. These values are defined as Python int, Python float, and Python complex
classes in Python.
Integers – This value is represented by int class. It contains positive or negative whole
numbers
The common convention(without
is to alias NumPy asfractions
`np`. or decimals). In Python, there is no limit to how long an
integer value can be. Example: X = 1
Float – This value is represented by the float class. It is a real number with a floating-
point representation. It is specified by a decimal point. Optionally, the character e or
E followed by a positive or negative integer may be appended to specify scientific
notation. Example: Y = 2.8
Complex Numbers – A complex number is represented by a complex class. It is
specified as (real part) + (imaginary part)j. For example – 2+3j
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Introduction - Numeric
Exercise
Numeric examples – (INT08)
Introduction - List
List: In Python, the sequence of various data types is stored in a list. A list is a built-in data
structure in Python, which is the collection of different kinds of values or items. Every
item in the list, also known as the Index, has an address allocated to it. The index value
begins at 0 and continues until the final component, which is the positive index. You can
also retrieve elements from last to first using negative indexing, which starts at -1.
Integers – This value is represented by int class. It contains positive or negative whole
The common convention is to alias NumPy as `np`.
Introduction - List
Exercise:
List – (INT09)
Modification of list – (INT10)
Length of list - (INT11)
Sorting of list - (INT11)
The common convention is to alias NumPy as `np`.
Reverse of list - (INT11)
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Introduction - Tuples
Tuples: A tuple is a built-in data structure in Python similar to lists but also has some significant
differences. The difference between the two is that once the elements are assigned to the tuple can’t
be changed. Tuples are used to store an ordered series of elements and are defined by parentheses
(). The most common associated method of tuples are tuple(), count(), index() etc. Tuples allow
duplicate values:
Examples of Tuple: thistuple = ("apple", "banana", "cherry", "apple", "cherry")
The common convention is to alias NumPy as `np`.
Introduction - Tuples
Exercise
Tuple – (INT12)
Tuple iterations – (INT13)
Tuple functions concatenate and repeating – (INT14)
Tuple coordinates – (INT15)
The common convention is to alias NumPy as `np`.
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Introduction – Dictionary
Dictionary: A dictionary in Python is a data structure that stores the value in value:key pairs. The most common
associated method of dictionaries are get(), keys(), values(), items(), update(), pop(), clear() etc.
Example: Dict = {1: ‘ICAI', 2: 'For', 3: ‘CA’}
As you can see from the example, data is stored in key: value pairs in dictionaries, which makes it easier to find
values.
Dictionary vs Json
Json Dictionary
The common convention is to alias NumPy as `np`.
JSON keys can only be strings. The dictionary’s keys can be any hashable object.
The keys in the dictionary cannot be repeated and must
The keys in JSON are ordered sequentially and can be repeated.
be distinct.
The keys in JSON have a default value of undefined. There is no default value in dictionaries.
The subscript operator is used to access the values in the
The values in a JSON file are accessed by using the “.” (dot) or
dictionary. For example, if ‘dict’ = ‘A’:’123R’,’B’:’678S’, we
“[]” operator.
can retrieve data related by simply calling dict[‘A’].
For string objects, we can use either a single or double
For the string object, we must use double quotation marks.
quotation.
The ‘dict’ object type is the return object type in a
In JSON, the return object type is a’string’ object type.
dictionary.
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Regex
Regex: A RegEx, or Regular Expression, is a sequence of characters that
forms a search pattern. RegEx can be used to check if a string contains
the specified search pattern.
RegEx Functions:
The common convention is to alias NumPy as `np`.
Function Description
findall Returns a list containing all matches
search Returns a Match object if there is a
match anywhere in the string
split Returns a list where the string has
been split at each match
sub Replaces one or many matches with a
string
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Regex
Meta Characters:
Character Description Example
[] A set of characters "[a-m]"
\ Signals a special sequence (can also be used to escape special "\d"
characters)
. Any character (except newline character) "he..o"
The common
^ convention is to alias
StartsNumPy as `np`.
with "^hello"
$ Ends with "planet$"
* Zero or more occurrences "he.*o"
+ One or more occurrences "he.+o"
? Zero or one occurrences "he.?o"
{} Exactly the specified number of occurrences "he.{2}o"
| Either or "falls|stays"
() Capture and group
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Regex
Special Sequences:
Character Description Example
\A Returns a match if the specified characters are at the beginning of the "\AThe"
string
\b Returns a match where the specified characters are at the beginning r"\bain"
or at the end of a word
(the "r" in the beginning is making sure that the string is being treated r"ain\b"
as a "raw string")
The common
\B convention is to alias NumPy as `np`.
Returns a match where the specified characters are present, but NOT r"\Bain"
at the beginning (or at the end) of a word
(the "r" in the beginning is making sure that the string is being treated r"ain\B"
as a "raw string")
\d Returns a match where the string contains digits (numbers from 0-9) "\d"
\D Returns a match where the string DOES NOT contain digits "\D"
\s Returns a match where the string contains a white space character "\s"
\S Returns a match where the string DOES NOT contain a white space "\S"
character
\w Returns a match where the string contains any word characters "\w"
(characters from a to Z, digits from 0-9, and the underscore _
character)
\W Returns a match where the string DOES NOT contain any word "\W"
characters
\Z Returns a match if the specified characters are at the end of the string "Spain\Z"
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Regex
Sets:
Set Description
[arn] Returns a match where one of the specified characters (a, r, or n) is present
[0123] Returns a match where any of the specified digits (0, 1, 2, or 3) are present
[a-zA-Z] Returns a match for any character alphabetically between a and z, lower
case OR upper case
[+] In sets, +, *, ., |, (), $,{} has no special meaning, so [+] means: return a
match for any + character in the string
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Regex
Exercises:
Regex Simple Match (REG01) – Search
Regex extract Email - (REG02)
Regex Split REG03
Regex Date Split REG04
The common convention is to alias NumPy as `np`.
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Python Datetime module comes built into Python, so there is no need to install it
externally.
Examples
The common convention is to alias NumPy as `np`.
Date – 01
Date -02
Date - 03
For further Reading :
[Link]
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Regex – Ai
Use any Ai tool like [Link]
Prompt
Explain the below attached regex patten
pattern = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-
]+\.[A-Z|a-z]{2,}\b'
The common convention is to alias NumPy as `np`.
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Equals: a == b
Not Equals: a != b
Less than: a < b
Less
common
The than
convention orNumPy
is to alias equal
as `np`.to: a <= b
These conditions can be used in several ways, most commonly in "if statements"
and loops. Python relies on indentation (whitespace at the beginning of a line) to
define scope in the code.
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Exercises:
While loop (FW01)
For loop (FW02)
The common convention is to alias NumPy as `np`.
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
File operations
“r” – Read
“w” – Write
“a” – Append
“x” – Create
The common convention is to alias NumPy as `np`.
Exercises:
“ r“ – FAR 01
“w” - FAR 02
“a” – FAR 03
“x” – FAR 04
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Learning Objectives
TO UNDERSTAND THE IMPORTANCE OF PYTHON LIBRARIES IN DATA ANALYSIS.
Introduction – Libraries
A python library is a collection of related modules.
It contains bundles of code that can be used repeatedly in different programs.
It makes python programming simpler and convenient for the programmer.
As we don’t need to write the same code again and again for different
programs.
Python libraries play a very vital role in fields of machine learning, data science,
data visualization, etc.
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Numpy
NumPy, short for "Numerical Python," is a foundational library for numerical and
scientific computing in the Python programming language.
Numpy
Array Representation
Data Storage
Vectorized Operations
Universal Functions (ufuncs)
Broadcasting
Indexing and Slicing
Mathematical Functions
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
ii. Transposing:
Transposing involves switching the rows and columns of a two-dimensional data structure like
a matrix or array. This operation is particularly useful for linear algebra operations or when
working with tabular data.
10. Broadcasting
NumPy allows you to perform operations on arrays of different shapes, often automatically
aligning their shapes, thanks to broadcasting rules.
Reshape arrays into different dimensions using np. reshape or the reshape method.
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
The name "Pandas" has a reference to both "Panel Data", and "Python Data
Analysis" and was created by Wes McKinney in 2008
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
[Link]()
[Link]()
[Link]
[Link]()
[Link]()
[Link](~)
These methods are invaluable for getting an initial sense of your data's structure
and Content.
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Viewing Data
Name_Column = df[`Name`
Subset = df[[‘Name’, ‘Age’]]
Young_People = df[df[“age”] <30]
Note: Loading data already discussed under Creating and Loading Data Frame
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
DATA REDUCTION
Dimensionality Reduction
Principal Component Analysis (PCA)
Feature Selection
Recursive Feature Elimination (RFE)
DATA IMBALANCE HANDLING
Oversampling
Undersampling
Synthetic Data Generation (SMOTE)
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Approach - 1
Using pandas data frame to read Json file and then write to excel
Approach – 2
Using openpyxl library read json parts and write to excel directly
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Approach - 1
Use XML Element tree Module
[Link]
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Students may use the excel file provided to consolidate into single file
Approach :
Approach :
Get Ledger Master Data from Tally data using sql Query
Query
Select $Name, $Parent, $_PRimaryGroup, $OpeningBalance, $_ClosingBalance
from Ledger
Libraries used
Pyodbc
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
DATA
VISUALIZATION
WITH PYTHON
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Learning Objectives
Basic Plots
LINE PLOT
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Basic Plots
SCATTER PLOT
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Basic Plots
HISTOGRAM
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Basic Plots
BAR PLOT
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Basic Plots
PIE PLOT
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
INDEPENDENT FEATURES
DEPENDENT FEATURES
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
TYPES OF ML ALGORITHMS
SUPERVISED ALGORITHM
UNSUPERVISED ALGORITHM
REINFORCEMENT LEARNING
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
TYPES OF ML ALGORITHMS
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
DATA
VISUALIZATION
WITH PYTHON
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Learning Objectives
Basic Plots
LINE PLOT
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Basic Plots
SCATTER PLOT
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Basic Plots
HISTOGRAM
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Basic Plots
BAR PLOT
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Basic Plots
PIE PLOT
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
Basic Plots
SUN BURST
Click Here & Join Now to Download the Latest CA Final Notes & Free Classes: [Link]
TH A N K
YOU