Scipy,Matplotlib,Pandas
Scipy,Matplotlib,Pandas
1)Numpy:
What is NumPy.
1. Less Memory
2. Fast
3. Convenient
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.
import numpy as np
print(arr[1:5])
Output: [2 3 4 5]
import numpy as np
2)Scipy
SciPy stands for Scientific Python.
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
Python.
Matplotlib Pyplot
Pyplot
Most of the Matplotlib utilities lies under
the pyplot submodule, and are usually imported under
the plt alias:
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.
Installing:
Series
DataFrame
Panel
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 −
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.