Data Analytics with Python

Syllabus

UNIT –I

PYTHON FUNDAMENTALS :1. Python Features, Python History, Python Applications, Python Installation, 2. Creating and saving a script file, 3. Commenting script files, 4. Variable creation, 5. Arithmetic and logical operators, 6. Data types and associated operations, 7. Assignment statement, Control Flow, Functions. 8. Strings, String functions, string processing, formatting printed output, 9. Array, Lists, Arrays vs lists ,10. Manipulating lists ,Tuples, Sorting, Set, Dictionaries, Range, Passing Functions, 11. Exception handling, input/output, file handling.

UNIT –II

PYTHON OOPS CONCEPTS AND INTRODUCTION TO DATA ANALYTICS: 1. Classes, objects and Constructors, 2. Inheritance, Abstraction in Python. 3. Introduction to data analytics, 4. Understanding the Domain, 5. Understanding the Dataset, 6. Python package for data science, 7. Basic Insights from Datasets

UNIT –III

IMPORTING DATASETS: 1. Importing and Exporting Data in Python, 2. Analyzing Data in Python, 3. Accessing Databases with Python DATA WRANGLING(CLEANING AND PREPARING THE DATA) : Identify and Handle Missing Values, Data Formatting Data Normalization Sets, Binning, Indicator variables, 4. Turning categorical variables into quantitative variables in Python.

UNIT –IV

EXPLORATORY DATA ANALYSIS: 1. Exploratory Data Analysis (Summarizing the Data Frame) Descriptive Statistics, 2. Basic of Grouping , 3. ANOVA , 4. Correlation, Correlation – Statistics , 5. Association between two categorical variables: Chi Square, 6. MODEL DEVELOPMENT: Model Development, 7. Linear Regression and Multiple Linear Regression, Model Evaluation using Visualization ,Polynomial Regression and Pipelines ,8. Measures for In-Sample Evaluation , Prediction and Decision Making

UNIT -V

MODEL EVALUATION: 1. Model Evaluation and Refinement, 2. Overfitting, 3. Underfitting and Model Selection, 4. Ridge Regression, 5. Grid Search

What is python?

Python is a general purpose, dynamic, high-level, and interpreted programming language. It supports Object Oriented programming approach to develop applications. It is simple and easy to learn.

  • Easy to learn and use
  • Interpreted language
  • Object-Oriented Programming Language
  • Open-Source Language
  • Dynamic Memory Allocation
  • Case Sensitive

 

Uses of python:

  • System scripting
  • Web development
  • Software development
  • Complex mathematics       

 

Data type: 

A data type represents the kind of value that tells what operations can be performed on that data.

Eg: int,float,str

  • Integer - Integer value can be like 10, 2, 29, -20, -150 etc. Python has no restriction on the length of an integer. Its value belongs to int .  
  • Float - Float is used to store floating-point numbers like 1.9, 9.902, 15.2, etc.  Its value belongs to float 
  • String: The string can be defined as the sequence of characters represented in the quotation marks. Its value belongs to str

 

How to know the type of the data in python?

Python provides us the type() function, which returns the type of the variable passed. To reveal the data type of the given data.

>type(<value>)

Eg: type (11): int

 

What is type casting in python?

Changing the type of expression in python is called type casting.

>float(<value>): decimal value

eg: 

1.float (1)

=>1.0

2.int (3.14)

=>3

 

What is Boolean value?

A Boolean is a data type which can take only 2 values. (True or False).

 

bool(1) = True              int(True)  = 1

bool(0) = False             int(False) = 0

 

Expressions and Variables:

An expression is a combination of variables operands and operators that python evaluates to produce another value.

 A variable is used to store the value in it. eg: a = 10, here 'a' is a variable.

Operators: Operators are the symbols that are assigned to values to perform mathematical and logical operations. 

Operand: Operand is the value to which the operators are assigned.


Compounds of data types:

1. List

  • Definition: An ordered sequence, mutable collection of elements. It is represented by '[ ]'.
  • Syntax: list = [1, 2, 3, 'hello']
  • Key Features:
    1. Supports indexing and slicing.
    2. Allows duplicate elements.
    3. Elements can be of different data types.

2. Tuple

  • Definition: An ordered, immutable collection of elements. Tuples are written as comma ',' separated elements within parenthesis '( )' 
  • Syntax: tuple = (1,2,3,'a','b')
  • Key Features:
    1. Supports indexing and slicing.
    2. Immutable, making it suitable for fixed collections.
    3. Allows duplicate elements.

3. Set

  • Definition: An unordered, mutable collection of unique elements. We can convert a list inti set by using type casting.
  • Syntax: set = {1, 2, 3, 'hello'}
  • Key Features:
    1. No duplicate elements are allowed.
    2. Does not support indexing or slicing.
    3. Useful for membership tests and eliminating duplicates.

4. Dictionary

  • Definition: An unordered, mutable collection of key-value pairs.
  • Syntax: dict = {'key1': 'value1', 'key2': 'value2'}
  • Key Features:
    1. Keys must be unique and immutable.
    2. Values can be of any data type and may duplicate.
    3. Ideal for storing data in a mapping format.

Condition and Branching:

A condition is a task given to a program and the condition takes the program to 2 possible values.

True or False

If the condition is satisfied then the program can go further and if the condition is not satisfied the program skips the condition

Branching statements in Python allows to control the flow of your program based on certain conditions.

 

1.if statement: if the statement is true then the condition in the parenthesis will be executed. 

>if(condition):

            statement


2.else statement: if the statement is false then the else statement is executed. 

>if(condition):

            statement

  else:

            statement


3.elseif (elif) statement:  when the first if statement isn't true, but you want to check for another condition. 

>if(condition):

            Statement

  elif(condition):

            statement

else:

            statement


Loops:

Loops are a block of code which continue itself until a certain condition is met. Loops are used to minimize the code and make the code more manageable. 

while loop: a while loop is used to execute a block of statements repeatedly until a given condition is satisfied but when the condition becomes false the loop executes the next line of the loop.

Key point of While Loop:
  1. A while loop repeatedly executes a block of code as long as a given condition is true.
  2. It does not have a fixed number of iterations but continues executing until the condition becomes false.
  3. The condition is checked before each iteration, and if it's false initially, the code block is skipped entirely.
  4. The condition is typically based on a variable or expression that can change during the execution of the loop.
  5. It provides more flexibility in terms of controlling the loop's execution based on dynamic conditions.

syntax:

while(<expression>):

        statement

 eg:

 a= 0

 while (a< 3):

         a =a + 1

 print ("while loop")


for loopfor loop runs in the given range. A for loop is used for iterating over a sequence. 

Key point of For Loop:

  1. A for loop iterates over a sequence (such as a list, string, or range) or any object that supports iteration.
  2. It has a predefined number of iterations based on the length of the sequence or the number of items to iterate over.
  3. It automatically handles the iteration and does not require maintaining a separate variable for tracking the iteration count.
  4. It simplifies the code by encapsulating the iteration logic within the loop itself.
  5. It is commonly used when you know the exact number of iterations or need to iterate over each item in a collection.

syntax:

for <var> in range():

        statement

eg:

   a = 10

   for i in range (0,10):

          print(i)

Break Statement : 

The break is a keyword in python which is used to bring the program control out of the loop. The break statement breaks the loops one by one. Break is used to abort the current execution of the program and the control goes to the next line after the loop.

Functions

Functions are reusable blocks of code designed to perform a specific task. They help make the code modular, efficient, and easier to understand.

Functions in Python are defined using the 'def' keyword.

a=1

def add(b):

return a+b

c=add(10)

=> 11

String Operations:

A string has escape sequences by which we can change the line or to make space between 2 strings. 
These are known as string escape sequence.

  1. \n : it takes the string to the next line.
  2. \t : it creates a space in between the strings.

String Method:

The strings in python have functions that can change the strings accordingly.

  1. upper() : make the whole string into uppercase.
  2. replace() : it replaces the string to the new string assigned.
  3. find() : the find function breaks the whole string into single characters and arrange them in array and finds thee exact string character we need.     


Class : 

A class is like a blueprint or template for creating objects. It defines what an object should have (attributes) and what it can do (methods). Think of it as a general description, like a "Car" blueprint. You can use it to create specific objects, such as a red Toyota or a blue Honda. Without a class, you cannot create objects.

Object :

An object is a specific instance of a class. It represents a real thing with actual values for its attributes and can perform actions using its methods. For example, a car with the brand "Toyota" and color "red" is an object of the "Car" class. Each object has its own data but follows the class's blueprint. You can create many objects from the same class.

Read Files with Open :

Python’s open() function is used to work with files by creating a file object to access and manipulate file data. To open a file, you provide the file path (which includes the file name and its directory) and a mode. Common modes include 'r' for reading, 'w' for writing, and 'a' for appending. For reading files, the mode 'r' is commonly used. Once opened, you can use the file object to access its properties, such as name to get the file name and mode to check the mode in which the file is open. It is important to close the file after use to free resources, which can be done using the close() method.

The better approach is to use a 'with' statement to open files. This ensures the file is automatically closed once all operations in the indented block are completed. The read() method reads the entire file as a single string, while readline() returns each line as a list element. The readline() method reads one line at a time. You can also loop through a file object to read and print each line individually.


Comments