Packages
Packages
Introduction
Installation of Python Library
Numpy
Pandas
2
Python is popular since it has a huge collection of libraries.
6
• NumPy, which stands for Numerical Short brief about Numpy:
Python, is a library consisting of
multidimensional array objects and a
• Author- Travis Oliphant
collection of functions for processing •First Release- 1995 (Released
those arrays. as Numeric; Changed to NumPy in
• NumPy is a powerful linear algebra library 2006)
for Python. • Stable Release- June, 2018
• Using NumPy, mathematical and logical • Written in- Python Programming, C
operations on arrays can be performed.
7
Why NumPy?
• In Python we have lists that serve the purpose of arrays, but
they are slow to process.
To b e done while
using numpy in
prog rams 8
Creating NumPy Arrays from Objects
• The most important features
of numpy is ndarray an n-
dimensional array, it is a grid
of values of the same kind.
• There are various ways to
create Numpy Arrays.
9
Create the following NumPy array ?
array([[1, 2, 3],
[3, 4, 5]])
Creating NumPy Arrays from Objects
1
0
11
shape attribute:The shape property of a ndarray is used to get the current shape(row
and column values in case of a matrix or 2-d array) of a given ndarray.
ndim attribute:The ndim property of a ndarray is used to get the dimensions of a
given ndarray.
itemsize attribute:The itemsize attribute is a ndarray attribute that returns the size of each item
in a ndarray in bytes. As an array contains elements of the same data type, the size of each
element in the memory block is also the same.
size attribute:The size property of a ndarray is used to get the no of elements of a given
ndarray.
12
13
To access elements from 2-D arrays we can use
comma separated integers representing the
dimension and the index of the element.
14
Slicing ID Array is similar to the slicing we
did with list,strings etc..
Slicing 2-D Arrays:
Example:
To slice the second element, slice elements
from index 0 to index 1
15
Reshaping means changing the shape of an array.
16
Where() method is used for searching an element in an array. It returns the index where the element
is present.
17
The NumPy ndarray object has a function called sort(), that will sort a specified
array.
18
• Pandas is a Python library that is used for faster data analysis, data
cleaning and data pre-processing.
• Pandas is built on top of numpy. So, numpy gets some superpower
with pandas.
• It provides various data structures and operations for
manipulating numerical data and time series.
• Pandas is fast and it has high performance & productivity for users.
• Installation and importing of pandas library is done same as what we
did with Numpy.
19
Pandas generally provide two data structures for manipulating data, They
are:
• Series
• DataFrame
Series:
Pandas Series is a one-dimensional labelled array capable of holding data of any
type (integer, string, float, python objects, etc.).
Dataframe:
Pandas DataFrame is a two-dimensional size-mutable, potentially heterogeneous
tabular data structure with labeled axes (rows and columns).
2
0
Dataframe:
Pandas DataFrame consists
of three principal components,
the data, rows, and columns.
21
Creating a DataFrame:
In the real world, a Pandas DataFrame will be created by loading the
datasets from existing storage,like SQL Database, CSV file, an Excel file.
Pandas DataFrame can be created from the lists, dictionary, and from a list of
dictionaries, etc.
22
Creating a DataFrame:
If we have some data in our CSV file and we want to read that, then we can
use the read_csv() method to read the data in pandas. You just need to pass
the file name or path as the parameter of the method.
23
Info about the dataset Statistics of the dataset
24
Display single column Display multiple columns
25
Create new column Drop a column
26
Python Packages