Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Numpy

What is numpy?
Numpy is a general-purpose array-processing package. It provides a high-performance
multidimensional array object, and tools for working with these arrays.
It is the fundamental package for scientific computing with Python. It contains various features
including these important ones:
 A powerful N-dimensional array object
 Sophisticated (broadcasting) functions
 Useful linear algebra, Fourier transform, and random number capabilities

How it is installed?
To install it on Ubuntu, run the following commands in terminal.
 sudo apt-get install python-pip3
 sudo pip3 install numpy scipy

Where it is used?
Python does not have built-in support for Arrays, but Python lists can be used instead:

array = ['hello', 'Hi']


print(array)

*But we wouldn't call it an array* it's still a list


Next comes Numpy to create multi-dimensional array(2D, 3D etc), now in order to achieve that,
Numpy must be supported in Python so we will import Numpy in the code editor (different code
editors have different styles of importing or in-built plugins to import Numpy)

Now create an array

import numpy as numbers


a = numbers.array([0,1,2,3,4,5])
print(a)

It should work just fine.

Next, for the 2D, 3D etc arrays in Numpy to calculate big data in terms of including columns and
rows:

import numpy as numbers


a = numbers.array([(0,1,2,3,4,5),(6,7,8,9,10,11)])
print(a)
What are the methods used in it?
Sr. # Name Description

This is one of the most important features of numpy. ndarray is


1 Ndarray an n-dimensional array, a grid of values of the same kind. A tuple
of nonnegative integers indexes this tuple. An array’s rank is its
number of dimensions.
This function is used when we want to convert input to an array.
2 Asarray Input can be lists, lists of tuples, tuples, tuples of tuples, tuples of
lists and ndarrays.
This function is used when we want to convert input to an array
3 Asanyarray but it pass ndarray  subclasses through. Input can be scalars, lists,
lists of tuples, tuples, tuples of tuples, tuples of lists and ndarrays.

Code Example?
import numpy as np
# Creating array object
arr = np.array( [[ 1, 2, 3],
[ 4, 2, 5]] )
# Printing type of arr object
print("Array is of type: ", type(arr))
# Printing array dimensions (axes)
print("No. of dimensions: ", arr.ndim)
# Printing shape of array
print("Shape of array: ", arr.shape)
# Printing size (total number of elements) of array
print("Size of array: ", arr.size)
# Printing type of elements in array
print("Array stores elements of type: ", arr.dtype)

Output :

Array is of type:
No. of dimensions: 2

Shape of array: (2, 3)

Size of array: 6

Array stores elements of type: int64

Pandas
What Is Pandas?
Pandas is a Python package providing fast, flexible, and expressive data structures designed to
make working with structured (tabular, multidimensional, potentially heterogeneous) and time
series data both easy and intuitive. It aims to be the fundamental high-level building block for
doing practical, real world data analysis in Python.

How it is Installed?
Pandas is install in windows using the following query in command line:
 pip install pandas

Where it is used?
In computer programming, pandas is a software library written for the Python programming
language for data manipulation and analysis. In particular, it offers data structures and operations
for manipulating numerical tables and time series. It is free software released under the three-
clause BSD license. Pandas is an open source Python package that provides numerous tools for
data analysis. The package comes with several data structures that can be used for many different
data manipulation tasks. It also has a variety of methods that can be invoked for data analysis,
which comes in handy when working on data science and machine learning problems in Python.

What are the methods used in it?


Sr. # Name Description

This function used to view some basic statistical details like


1 Dataframe.describe() percentile, mean, std etc. of a data frame or a series of numeric
values. When this method is applied to a series of string, it
returns a different output
This is one of the general functions in Pandas which is used to
2 pandas.period_range() return a fixed frequency PeriodIndex, with day (calendar) as
the default frequency.
3 pandas.to_numeric This is one of the general functions in Pandas which is used to
convert argument to a numeric type.

This is used to map values from two series having one column
4 same. For mapping two series, the last column of the first
pandas.map() series should be same as index column of the second series,
also the values should be unique.

Code Example?
# Program to create Dataframe of three series
import pandas as pd
s1 = pd.Series([1, 3, 4, 5, 6, 2, 9]) # Define series 1
s2 = pd.Series([1.1, 3.5, 4.7, 5.8, 2.9, 9.3]) # Define series 2
s3 = pd.Series(['a', 'b', 'c', 'd', 'e']) # Define series 3
Data ={'first':s1, 'second':s2, 'third':s3} # Define Data
dfseries = pd.DataFrame(Data)  # Create DataFrame

Output

Matplotlib
What is Matplotlib function?
matplotlib.pyplot is a collection of command style functions that make matplotlib work like
MATLAB. Each pyplot function makes some change to a figure: e.g., creates a figure, creates a
plotting area in a figure, plots some lines in a plotting area, decorates the plot with labels, etc.
How it is installed?
Matplotlib is install in windows using the following query in command line:
 pip install matplotlib

Where it is used?
matplotlib. pyplot is a plotting library used for 2D graphics in python programming language. It
can be used in python scripts, shell, web application servers and other graphical user interface
toolkits. There are several toolkits which are available that extend python
matplotlib functionality

What are the methods used in it?


matplotlib.pyplot.plotting()
Sr. # Name Description

1 acorr Plot the autocorrelation of x


2 angle_spectrum Plot the angle spectrum
3 annotate Annotate the point xy with text text.

4 arrow Add an arrow to the axes.

5 autoscale Autoscale the axis view to the data (toggle).

Code Example?
# importing matplotlib module
from matplotlib import pyplot as plt
# x-axis values
x = [5, 2, 9, 4, 7]
# Y-axis values
y = [10, 5, 8, 4, 2]
# Function to plot
plt.plot(x,y)
# function to show the plot
plt.show()
Output

You might also like