Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Scipy,Matplotlib,Pandas

The document provides an overview of key Python libraries for scientific computing: NumPy, SciPy, Matplotlib, and Pandas. It explains NumPy's array capabilities, SciPy's mathematical functions, Matplotlib's plotting functionalities, and Pandas' data manipulation structures. Each library is described with its purpose, basic functions, and examples of usage.

Uploaded by

prasad wadkar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Scipy,Matplotlib,Pandas

The document provides an overview of key Python libraries for scientific computing: NumPy, SciPy, Matplotlib, and Pandas. It explains NumPy's array capabilities, SciPy's mathematical functions, Matplotlib's plotting functionalities, and Pandas' data manipulation structures. Each library is described with its purpose, basic functions, and examples of usage.

Uploaded by

prasad wadkar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Standard Packages

1)Numpy:
What is NumPy.

NumPy stands for Numerical Python.

NumPy was created in 2005 by Travis Oliphant. It is an open


source project and you can use it freely.

It is the core library for scientific computing, which contains a


powerful n-dimensional array object.

Python NumPy Array: Numpy array is a powerful N-dimensional


array object which is in the form of rows and columns. We can
initialize NumPy arrays from nested Python lists and access it
elements

In Numpy array,individual data items are called elements, all


elements should have same datatype.Array can be made up of any
number of Dimensions.

In Numpy Dimensions are called Axes.The size of Numpy array is


fixed,once created it cannot be changed.

We use python NumPy array instead of a list because of the below


three reasons:

1. Less Memory
2. Fast
3. Convenient

Numpy ‘s array class is called as ndarray.It is also know by the alias


array.

NumPy is used to work with arrays. The array object in NumPy


is called ndarray.

Basic Attributes of the ndarray class:

Attributes Description
Shape A tuple that specifies the number of elements
for each dimension of the array
size The total number elements in the array.
ndim Determines the dimensions an array
nbytes Number of bytes used to store data
dtype Determines the datatype of elements stored
in array.

Reshaping of Array:
Reshaping means changing the shape of an array. The
shape of an array is the number of elements in each
dimension.Which gives new look.
>>> arr1=np.array, ([[1,23],[4,5,6]])
>>> a=arr1.reshape(3,2)
>>> a
array([[1, 2],
[3, 4],
[5, 6]])

Slicing arrays
Slicing in python means taking elements from one given index
to another given index.

We pass slice instead of index like this: [start:end].

We can also define the step, like this: [start:end:step].

If we don't pass start its considered 0

If we don't pass end its considered length of array in that


dimension

If we don't pass step its considered 1

 Slice elements from index 1 to index 5 from the following


array:

import numpy as np

arr = np.array([1, 2, 3, 4, 5, 6, 7])

print(arr[1:5])

Output: [2 3 4 5]

 Slice elements from index 4 to the end of the array:

import numpy as np

arr = np.array([1, 2, 3, 4, 5, 6, 7])


print(arr[4:])
Output: [5 6 7]

2)Scipy
SciPy stands for Scientific Python.

SciPy is built on the Python NumPy extention. SciPy is also pronounced as


“Sigh Pi.”
SciPy in Python is an open-source library used for solving mathematical,
scientific, engineering, and technical problems.
It allows users to manipulate the data and visualize the data using a wide range
of high-level Python commands.

SciPy was created by NumPy's creator Travis Olliphant.

SciPy module in Python is a fully-featured version of Linear Algebra while


Numpy contains only a few features.

Cubic Root Function:


Cubic Root function finds the cube root of values.

Syntax:
scipy.special.cbrt(x)

Example:
from scipy.special import cbrt
#Find cubic root of 27 & 64 using cbrt() function
cb = cbrt([27, 64])
#print value of cb
print(cb)
Output: array([3., 4.])
Linear Algebra with SciPy
 Linear algebra routine accepts two-dimensional array
object and output is also a two-dimensional array.
Calculating determinant of a two-dimensional matrix,
from scipy import linalg
import numpy as np
#define square matrix
Arr2= np.array([ [4,5], [3,2] ])
#pass values to det() function
linalg.det(Arr2)

Output: -7.0

3) Matplotlib

Matplotlib is easy to use and an amazing visualizing library in

Python.

It is built on NumPy arrays and designed to work with the

broader SciPy stack and consists of several plots like line,

bar, scatter, histogram, etc.


Matplotlib was created by John D. Hunter.

Matplotlib is open source and we can use it freely.

Matplotlib Pyplot
Pyplot
Most of the Matplotlib utilities lies under
the pyplot submodule, and are usually imported under
the plt alias:

import matplotlib.pyplot as plt


or
from matplotlib import pyplot as plt

Line plot :
# Function to plot
plt.plot(x,y)
# function to show the plot
plt.show()
Bar Graph: The bar() function takes arguments that
describes the layout of the bars.
The categories and their values represented by
the first and second argument as arrays.


Histogram:
A histogram is a graph showing frequency distributions.

Histogram is useful when we have very long list.

A Histogram is a special graph that uses vertical colums to


show frequencies(how many times each score occurs)

It is a graph showing the number of observations within each


given interval. In Matplotlib, we use the hist() function to
create histograms.
Scatter Plot
With Pyplot, you can use the scatter() function to draw a
scatter plot.

The scatter() function plots one dot for each observation

The data is displayed as a collection of points,each


having the value of one variable which determines the
position on the horizontal axis and the value of other
variable determines the position on the vertical axis.
Pandas
Pandas is a Python library used for working with data sets.

It has functions for analyzing, cleaning, exploring, and


manipulating data.
The name "Pandas" has a reference to both "Panel Data", and
"Python Data Analysis" and was created by Wes McKinney in
2008.

Installing:

Pip install pandas

Pandas deals with the following three data structures −

 Series
 DataFrame
 Panel

Data Dimensions Description


Structure

Series 1 1D labeled homogeneous array, sizeimmutable.

Data 2 General 2D labeled, size-mutable tabular structure


Frames with potentially heterogeneously typed columns.

Panel 3 General 3D labeled, size-mutable array.

Series : Pandas Series is a one-dimensional array capable of


holding data of any type (integer, string, float, python objects,
etc.).

The axis labels are collectively called indexes. Pandas Series


is nothing but a column in an excel sheet

pandas.Series
A pandas Series can be created using the following constructor −
pandas.Series( data, index, dtype, copy)
The parameters of the constructor are as follows −

Sr.N Parameter & Description


o

1 data
data takes various forms like ndarray, list, constants

2 index
Index values must be unique and hashable, same length as data.
Default np.arrange(n) if no index is passed.

3 dtype
dtype is for data type. If None, data type will be inferred

4 copy
Copy data. Default False
Pandas Data Frames
Sr.N Parameter & Description
o

1 data
data takes various forms like ndarray, series, map, lists, dict, constants
and also another DataFrame.

2 index
For the row labels, the Index to be used for the resulting frame is
Optional Default np.arange(n) if no index is passed.

3 columns
For column labels, the optional default syntax is - np.arange(n). This is
only true if no index is passed.

4 dtype
Data type of each column.

5 copy
This command (or whatever it is) is used for copying of data, if the
default is False.

A Data frame is a two-dimensional data structure, i.e., data is


aligned in a tabular fashion in rows and columns.
pandas.DataFrame( data, index, columns, dtype, copy)
The parameters of the constructor are as follows −

You might also like