0% found this document useful (0 votes)
9 views27 pages

Python For Data Science

Uploaded by

harimeena828
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views27 pages

Python For Data Science

Uploaded by

harimeena828
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 27

THIRUTHANGAL NADAR COLLEGE

VALUE ADDED COURSE


PYTHON FOR DATA SCIENCE
MENTOR
V.SHEELA
INTRODUCTION TO DATA
SCIENCE
• Data science is the study of data that helps us derive useful insight
for business decision making. Data Science is all about using tools,
techniques, and creativity to uncover insights hidden within data. It
combines math, computer science, and domain expertise to tackle
real-world challenges in a variety of fields.
• Data Science processes the raw data and solve business problems
and even make prediction about the future trend or requirement. For
example, from the huge raw data of a company, data science can
help answer following question:
• What do customer want?
• How can we improve our services?
• What will the upcoming trend in sales?
• How much stock they need for upcoming festival.
INTRODUCTION TO DATA
SCIENCE
Data science involves these key
steps
• Data Collection: Gathering raw data from various
sources, such as databases, sensors, or user
interactions.
• Data Cleaning: Ensuring the data is accurate, complete,
and ready for analysis.
• Data Analysis: Applying statistical and computational
methods to identify patterns, trends, or relationships.
• Data Visualization: Creating charts, graphs, and
dashboards to present findings clearly.
• Decision-Making: Using insights to inform strategies,
create solutions, or predict outcomes.
Why Is Data Science Important?

• Why Is Data Science Important?


• In a world flooded with user-data, data science is crucial for driving progress
and innovation in every industry. Here are some key reasons why it is so
important:
• Helps Business in Decision-Making: By analyzing data, businesses can
understand trends and make informed choices that reduce risks and
maximize profits.
• Improves Efficiency: Organizations can use data science to identify areas
where they can save time and resources.
• Personalizes Experiences: Data science helps create customized
recommendations and offers that improve customer satisfaction.
• Predicts the Future: Businesses can use data to forecast trends, demand,
and other important factors.
• Drives Innovation: New ideas and products often come from insights
discovered through data science.
• Benefits Society: Data science improves public services like healthcare,
education, and transportation by helping allocate resources more effectively.
Arithmetic Operators

• Used for mathematical calculations.


– + (Addition)
– - (Subtraction)
– * (Multiplication)
– / (Division)
– % (Modulus - returns the remainder of a division)
– ** (Exponentiation - raises the first operand to the
power of the second)
– // (Floor Division - divides and returns the integer part
of the quotient)
Assignment Operators:

• Used to assign values to variables.


= (Assignment)
+=, -=, *=, /=, %=, **=, //= (Combined
arithmetic and assignment)
Logical Operators
• Used to combine conditional statements.
– and (Logical AND)
• or (Logical OR)
• not (Logical NOT)
Why Is Data Science Important?

• In a world flooded with user-data, data science is crucial for driving progress
and innovation in every industry. Here are some key reasons why it is so
important:
• Helps Business in Decision-Making: By analyzing data, businesses can
understand trends and make informed choices that reduce risks and
maximize profits.
• Improves Efficiency: Organizations can use data science to identify areas
where they can save time and resources.
• Personalizes Experiences: Data science helps create customized
recommendations and offers that improve customer satisfaction.
• Predicts the Future: Businesses can use data to forecast trends, demand,
and other important factors.
• Drives Innovation: New ideas and products often come from insights
discovered through data science.
• Benefits Society: Data science improves public services like healthcare,
education, and transportation by helping allocate resources more effectively.
Built-in Data Types in Python
• Numeric Types:
– int: Whole numbers (e.g., 5, -100).
– float: Decimal numbers (e.g., 3.14, -0.5).
– complex: Complex numbers (e.g., 1 + 2j).
• Text Type:
– str: Sequences of characters, enclosed in single or double quotes
(e.g., "Hello", 'Python').
• Sequence Types:
– list: Ordered, mutable collections of items, enclosed in square brackets (e.g., [1,
2, 3], ["apple", "banana"]).
– tuple: Ordered, immutable collections of items, enclosed in parentheses (e.g., (1,
2, 3), ("red", "green")).
– range: Immutable sequence of numbers, often used in loops (e.g., range(5)).
• Mapping Type:
– dict: Unordered collections of key-value pairs, enclosed in curly braces
(e.g., {"name": "John", "age": 30}).
• Set Types:
– set: Unordered collections of unique items, enclosed
in curly braces (e.g., {1, 2, 3}).
– frozenset: Immutable version of a set.
• Boolean Type:
– bool: Represents truth values, either True or False.
• Binary Types:
– bytes, bytearray, memoryview: Used for handling
binary data.
• None Type:
– NoneType: Represents the absence of a value,
with None being the sole instance.
Bitwise Operators

• Used to perform operations at the binary (bit)


level on integers.
– & (Bitwise AND)
• | (Bitwise OR)
• ^ (Bitwise XOR)
• ~ (Bitwise NOT)
• << (Left shift)
• >> (Right shift)
Membership Operators

• Used to test whether a value or variable is


found in a sequence (e.g., string, list,
tuple, set, dictionary).
– in
• not in
Identity Operators

• Used to check if two variables refer to the


same object in memory.
– is
• is not
WEEK
• Sequence data types are ordered
collections of items, where each item can
be accessed by its position (index). They
allow for storing multiple values in a
structured manner and support common
operations like indexing, slicing,
concatenation, and repetition.
Contd…
• The primary sequence data types in Python
include:
• Strings (str): Immutable sequences of
characters.
• Python
• my_string = "Hello"
• Lists (list): Mutable, ordered collections of
items. They can contain elements of different
data types.
• Python
• my_list = [1, "apple", 3.14]
Contd…
• Tuples (tuple): Immutable, ordered collections of items, similar to lists but
cannot be modified after creation.
• Python
• my_tuple = (1, "banana", 2.71)
• Range Objects (range): Immutable sequences of numbers, commonly used
for iterating in loops.
• Python
• my_range = range(5) # Represents numbers from 0 to 4
• Bytes (bytes): Immutable sequences of single bytes (integers in the range 0-
255).
• Python
• my_bytes = b"hello“
• Bytearrays (bytearray): Mutable sequences of single bytes, similar to bytes
but can be modified.
• Python
• my_bytearray = bytearray(b"world")
Key Characteristics of Sequence
Types
• Ordered: Elements maintain a specific order.
• Indexed: Elements can be accessed using integer
indices (starting from 0 for the first element).
• Iterable: Elements can be iterated over using loops.
• Support Slicing: Subsequences can be extracted using
slicing (e.g., my_list[1:3]).
• Mutability: Sequences can be either mutable (like lists
and bytearrays, allowing modification after creation) or
immutable (like strings, tuples, bytes, and range objects,
which cannot be changed once created).
Common Sequence Operations
• 1. Accessing Elements:
– Indexing: Retrieving a specific element using
its index (e.g., my_list[2] to get the third
element).
– Slicing: Extracting a portion of the sequence
as a new sequence (e.g., my_list[1:4] to get
elements from index 1 up to (but not
including) index 4).
Sequence Manipulation

• Concatenation: Combining two


sequences into a new sequence (e.g., [1,
2] + [3, 4] results in [1, 2, 3, 4]).
• Repetition: Repeating a sequence a
specified number of times (e.g., [1, 2] *
3 results in [1, 2, 1, 2, 1, 2]).
• Length: Determining the number of
elements in a sequence
(e.g., len(my_list)).
Contd..
• 3. Iteration:
– For Loops: Iterating through each element of the sequence
(e.g., for element in my_list: ...).
• 4. Other Useful Operations:
– min() and max(): Finding the smallest and largest elements in
a sequence (if the elements are comparable).
– sum(): Calculating the sum of all elements in a sequence (if
the elements are numbers).
• Examples:
• Lists (Mutable): Python lists are a versatile sequence
type that allows adding, removing, and modifying
elements after creation.
NumPy(Numerical Python)
• NumPy(Numerical Python) is a
fundamental library for Python numerical
computing. It provides efficient multi-
dimensional array objects and various
mathematical functions for handling large
datasets making it a critical tool for
professionals in fields that require heavy
computation.
Key Features of NumPy

• NumPy has various features that make it popular over lists.


• N-Dimensional Arrays: NumPy's core feature is ndarray, a
powerful N-dimensional array object that supports homogeneous
data types.
• Arrays with High Performance: Arrays are stored in contiguous
memory locations, enabling faster computations than Python
lists (Please see Numpy Array vs Python List for details).
• Broadcasting: This allows element-wise computations between
arrays of different shapes. It simplifies operations on arrays
of various shapes by automatically aligning their dimensions
without creating new data.
• Vectorization: Eliminates the need for explicit Python loops by
applying operations directly on entire arrays.
• Linear algebra: NumPy contains routines for linear algebra
operations, such as matrix multiplication, decompositions, and
determinants.
Installing NumPy in Python

• To begin using NumPy, you need to install


it first. This can be done through pip
command:
• pip install numpy
• Once installed, import the library with the
alias np
• import numpy as np
Creating NumPy Arrays

• Using ndarray : The array object is called ndarray.


NumPy arrays are created using the array() function.
• Example:
• import numpy as np
• ​# Creating a 1D arrayx = np.array([1, 2, 3])​# Creating a
2D arrayy = np.array([[1, 2], [3, 4]])​# Creating a 3D
arrayz = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])​
print(x)print(y)print(z)

Output[1 2 3] [[1 2] [3 4]] [[[1 2] [3 4]] [[5 6] [7 8]]]

• Using Numpy Functions: NumPy provides convenient
methods to create arrays initialized with specific values
like zeros and ones:
• Example:
• import numpy as np
• ​a1_zeros = np.zeros((3, 3))a2_ones = np.ones((2,
2))a3_range = np.arange(0, 10, 2)​
print(a1_zeros)print(a2_ones)print(a3_range)

Output[[0. 0. 0.] [0. 0. 0.] [0. 0. 0.]] [[1. 1.] [1. 1.]] [0 2 4 6
8]

NumPy Array Indexing

• Knowing the basics of NumPy array indexing is important for


analyzing and manipulating the array object.
• Basic Indexing: Basic indexing in NumPy allows you to access
elements of an array using indices.
• Example:
• import numpy as np
• ​# Create a 1D arrayarr1d = np.array([10, 20, 30, 40, 50])​# Single
element accessprint("Single element access:", arr1d[2]) ​# Negative
indexingprint("Negative indexing:", arr1d[-1]) ​# Create a 2D
arrayarr2d = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])​# Multidimensional
array accessprint("Multidimensional array access:", arr2d[1, 0])

OutputSingle element access: 30 Negative indexing: 50
Multidimensional array access: 4

You might also like