Numpyand Pandas
Numpyand Pandas
Data analytics is the process of examining and analyzing large and complex data sets
to extract useful insights and knowledge that can help in making informed decisions. In
this process, various statistical and computational techniques are used to transform,
clean, and process raw data into meaningful insights.
Types of Data:
There are two types of data: qualitative and quantitative data. Qualitative data is
descriptive and non-numerical data that is difficult to measure, such as opinions,
attitudes, and behaviors. On the other hand, quantitative data is numerical data that can
be measured and analyzed, such as height, weight, income, and sales figures.
Importance of Data:
Elements of Analytics:
The four main elements of analytics are data, tools, people, and processes. These
elements work together to help organizations make informed decisions based on data
insights.
The data analysis process involves several steps, including data collection, data
cleaning, data transformation, data modeling, data visualization, and data interpretation.
Qualitative analysis involves analyzing non-numerical data, such as text, images, and
videos. It involves identifying patterns, themes, and concepts in the data. Quantitative
analysis involves analyzing numerical data using statistical techniques, such as
regression analysis and hypothesis testing.
Installation:
NumPy can be installed using pip, which is a package installer for Python. Simply open
your command prompt or terminal and type "pip install numpy". This will install the
latest version of NumPy on your system.
Ndarray:
The ndarray is the most important object in NumPy. It is a multidimensional array of
elements, all of the same type, indexed by a tuple of positive integers. It can be created
using the numpy.array() function.
Creating an array:
We can create a NumPy array by passing a list or tuple to the numpy.array() function.
import numpy as np
NumPy also provides several intrinsic functions for creating arrays of different shapes
and sizes. Some of the commonly used intrinsic functions are:
Data types:
NumPy arrays can hold elements of different data types, such as integers, floating-point
numbers, and complex numbers. The dtype parameter can be used to specify the data
type of the array.
import numpy as np
import numpy as np
print(arr1 + arr2)
print(arr1 - arr2)
print(arr1 * arr2)
print(arr1 / arr2)
[5 7 9]
[-3 -3 -3]
[ 4 10 18]
[0.25 0.4 0.5 ]
Aggregate functions:
NumPy provides several aggregate functions that can be used to perform operations on
arrays, such as finding the sum, mean, median, maximum, minimum, and more.
import numpy as np
print(np.sum(arr))
print(np.mean(arr))
print(np.median(arr))
print(np.max(arr))
print(np.min(arr))
15
3.0
3.0
5
1
NumPy arrays can be indexed and sliced just like Python lists. Iterating through a
NumPy array can be done using a for loop.
import numpy as np
print(arr[0]) # output: 1
print(arr[1:3]) # output: [2 3]
import numpy as np
Array manipulation:
NumPy provides several functions for manipulating arrays, such as joining, splitting,
shape changing, sorting, and more.
Joining:
import numpy as np
print(np.concatenate((arr1, arr2)))
import numpy as np
a = np.zeros((2, 3))
print(a)
[[0. 0. 0.]
[0. 0. 0.]]
a = np.array([1, 2, 3])
for x in a:
print(x)
Array manipulation:
NumPy provides several functions for array manipulation, such as joining, splitting,
shape changing, and sorting.
Joining:
We can join two or more arrays using the numpy.concatenate() function. For example,
to join two 1-dimensional arrays, we can use the following code:
import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = np.concatenate((a, b))
print(c)
[1 2 3 4 5 6]
Splitting:
We can split an array into two or more arrays using the numpy.split() function. For
example, to split a 1-dimensional array into two arrays, we can use the following code:
import numpy as np
a = np.array([1, 2, 3, 4, 5, 6])
b = np.split(a, 2)
print(b)
Shape changing:
We can change the shape of an array using the numpy.reshape() function. For example,
to reshape a 1-dimensional array into a 2-dimensional array, we can use the following
code:
import numpy as np
a = np.array([1, 2, 3, 4, 5, 6])
print(b)
[[1 2 3]
[4 5 6]]
Sorting:
We can sort the elements of an array using the numpy.sort() function. For example, to
sort the elements of a 1-dimensional array in ascending order, we can use the following
code:
import numpy as np
a = np.array([3, 2, 1])
b = np.sort(a)
print(b)
[1 2 3]