Data Scientists across the world use Python as their go-to programming language for Data Science. This is due to the presence of a vast set of libraries that offers solutions to every problem in the stream of Data Science. And also due to the fact that Python is easy to learn and use, due to its spoken language-like syntax. All these make python a powerful tool for Data Science.
There is a self assessment test at the end of this article. Take that test and assess your knowledge related to Python Libraries for Data Science after reading this article.
What makes python so powerful and popular is its Data Science libraries. These include Pandas, NumPy, and Scikit-Learn which offer functions that turn insights from your data into magical tools that you can use for your business purposes.
In this article, we will learn about the 11 most important Python libraries for Data Science, which would help you to become a successful Data Scientist. We will be also discussing its installation, important functions, and code.
Before we begin if you want to learn more about Data Science read the below articles.
- Introduction to Data Science
- Languages and Tools you should know to become a Data Scientist
- Tools for Data Science
- Statistics for Data Science – Descriptive Statistics
- Complete Data Science Roadmap – With resources
- Introduction To Natural Language Processing
Learn about the providers of online masters in data science by clicking here
Let’s dive deep into the 11 most essential python libraries you must learn to become a successful Data Scientist.
1. NumPy
Used by Data scientists across the world for scientific computing, Numpy is a powerful open-source library written in C programming language. NumPy provides data structures like multidimensional arrays, matrices, etc., for various math operations. As a result, NumPy is the base library for various powerful data science libraries. Therefore Learning NumPy should be one of your first steps in becoming a Data Scientist. Even though it seems a bit similar to python lists, it consumes lesser memory and is way faster than a list.
Visit the official NumPy website to know more.
Installation
If you have already installed python on your machine then go to the terminal(cmd in windows) and type the following code.
pip install numpyOr if you have anaconda installed on your machine then open the anaconda prompt and type the following code.
conda install -c anaconda numpyExample code
If you have installed anaconda in your machine, then you can use Jupiter notebook to test these codes. Or you can use any other code editor as per your wish.
1. Creating an array
The following code is used to create a NumPy array.
Code :
#importing the library
import numpy as np
a = np.array([(8, 9, 10), (11, 12, 13)])
print(a)output:
[[8 9 10]
[11 12 13]]2. min and max:
These functions return the minimum and maximum value of the numbers in a NumPy array.
Code :
arr = np.array([1,2,3,4,5])
print(np.max(arr), np.min(arr))Output :
5 13. std:
This function returns the standard deviation of the numbers in a NumPy array.
Code :
arr = np.array([1,2,3,4,5])
print(np.std(arr))Output :
1.41421356237309514. mean:
This function returns the mean value of the numbers in a NumPy array.
Code:
arr = np.array([1,2,3,4,5])
print(np.mean(arr))Output:
3.05. median:
This function returns the median of the numbers in a NumPy array.
Code :
arr = np.array([1,2,3,4,5])
print(np.median(arr))Output :
3.06. percentile:
This function returns the percentile of the numbers in a NumPy array. Which is the number under which that percentage of numbers resides.
Code :
arr = np.array([1,2,3,4,5])
print(np.percentile(arr,25)) #prints 25th percentile
print(np.percentile(arr,50)) #prints 50th percentile
print(np.percentile(arr,75)) #prints 75th percentileOutput
2.0
3.0
4.07. linspace:
This function gives evenly spaced numbers within a specified interval.
Code:
print(np.linspace(2.0, 3.0, num=5, retstep=True))
"""
Here 2 is the lower limit and 3 is the upper limit.
Num=5 means we need to generate 5 numbers between 2 and 3.
retstep = True means the stepcount is returned.
"""Output :
(array([2. , 2.25, 2.5 , 2.75, 3. ]), 0.25)
"""
Here 0.25 is the step count.
"""8. shape:
This function returns the shape of an array.
Code :
arr = np.array([[1,2,3,4,5],[6,7,8,9,10]])
print(arr)
print(np.shape(arr))Output :
[[ 1 2 3 4 5]
[ 6 7 8 9 10]]
(2, 5) #Two rows and 5 columns9. reshape:
This function used to reshape a NumPy array.
Code :
arr = np.array([[1,2,3,4,5],[6,7,8,9,10]])
print(arr,"\n")
print(arr.reshape(5,2))Output :
[[ 1 2 3 4 5]
[ 6 7 8 9 10]]
[[ 1 2]
[ 3 4]
[ 5 6]
[ 7 8]
[ 9 10]]10. transpose:
This function is used to reverse the axes of the NumPy array.
Code :
arr = np.array([[1,2,3,4,5],[6,7,8,9,10]])
print(arr,"\n")
print(np.transpose(arr))Output :
[[ 1 2 3 4 5]
[ 6 7 8 9 10]]
[[ 1 6]
[ 2 7]
[ 3 8]
[ 4 9]
[ 5 10]]11. sort:
This function is used for sorting the NumPy array.
Code :
arr = np.array([11,2,30,4,5])
print(arr, "\n")
print(np.sort(arr))Output :
[11 2 30 4 5]
[ 2 4 5 11 30]2. SciPy
SciPy which stands for Scientific Python is a scientific computation library that is designed on top of NumPy. It provides functions that can be used to find mathematical formulas like the determinant of a matrix, eigenvalues, Eigenvectors, etc. Written in Python programming language it is slower than NumPy but provides much more functionalities. It is also used for solving problems like integration, optimization, linear algebra, and statistics.
Visit the official SciPy website to know more.
Installation
For the python environment use the following code.
pip install scipyFor the conda environment use the following code.
conda install -c anaconda scipyExample Code
Here we would see some examples of using the library.
Importing the necessary libraries
We would start by importing the libraries we would be using in these example codes.
import numpy as np
from scipy import linalgNow we would see the code to do different functions using this library.
1. Code to find the Determinant of a Matrix.
arr = np.array([[4,2,3],[4,5,6],[9,8,9]]) #creating a matrix using numpy
linalg.det(arr)Output :
-15.02. Code to find the Eigen values and Eigen vectors of this matrix.
We would be using the array we have built above to find these.
eig_vals, eig_vects = linalg.eig(arr)
print(eig_vals)
print(eig_vects)Output :
[16.88108059+0.j 1.65561839+0.j -0.53669898+0.j]
[[-0.26938637 -0.68838898 -0.19730392]
[-0.5048473 0.72319052 -0.65139713]
[-0.82009767 0.05582181 0.73263425]]3. Matplotlib
Data Visualization is an important skill set to have in becoming a successful Data Scientist. And its examples include bar graphs, pie charts, scatter plots, etc. Data Scientists use these graphs to easily understand insights from data.
Matplotlib is an open-source library built on NumPy arrays. It is a comprehensive library that consists of several plots like line, bar, scatter, histogram, etc. To know more about this visit the official Matplotlib website.
Installation
For the python environment use the following code.
pip install matplotlibContinue reading with KIE Premium
Unlock this article and all KIE premium articles.
Now or Never
We’ve got your back on your manufacturing journey — Stay in touch
Follow us for step-by-step guidance, templates, and insights that save time and reduce mistakes.
Know Industrial Engineering Platform – Helping manufacturing industry professionals worldwide since 2019
Very useful article, especially for beginners in python
Thank you Meet