5 Essential Python-Beginner Libraries You Should Know

As a Python beginner, you see videos and tutorials on YouTube or maybe read a blog, just like now. In such tutorial videos/blogs, you come across many Python libraries that may or may not be popular. For instance, you might have heard of Numpy library which is great for mathematical operations. However, relatively few of you might have heard of Pandas, which is a library meant for data processing and analysis.

In this fathomless ocean of available Python libraries, it can get overwhelming as a Python beginner to get familiar with all of them. This blog will show 5 basic yet essential Python libraries that you should know as a Python beginner. But before we begin, I would like to introduce to an amazing beginner-friendly Python book that would be helpful for you beyond this blog.

python libraries you should know

PyBites Python Tips features 250 bulletproof Python tips that promise to improve your coding skills. This book offers quick, practical code snippets that make learning Python enjoyable and accessible. What I find amazing about this book is that you can read the book in whatever order you want, and you don’t have to start from the beginning. Just pick the topic you find interesting and get started. Moreover, as the name of the book suggests, it contains simple tricks and tips on Python programming, which makes learning fast and fun. You might think it should be costly as programming books cost $20+. Well, your_guess != True. It costs only $7.99. Read more on what’s inside of the book here and decide for yourself.

Returning to this blog article, below are the topics that we will have a look at today:

1. Numpy

Numpy is the most basic and most commonly used library used by Python programmers. There’s a high chance that you are already familiar with this library as it is the first library we come across while learning Python.

Numpy takes over most, if not all, of the mathematical operations that are required in programming. Its wide range of functionalities makes it suitable for even some of the machine learning applications. With Numpy library, some of the challenging topics of math can be understood in a fun way. Go check out my article “An intuitive understanding of Eigenvalues and Eigenvectors where I used this library to understand eigenvalues and eigenvectors in linear algebra. If you are interested, check out other topics on Mathematics for Machine Learning where I’ve used this library to understand some important mathematical concepts visually.

Returning to this topic, below is a simple Python code to create an array using numpy library. In the code, you’ll also find simple operations like square() and sum() that you can carry out on that array.

import numpy as np

# Creating a NumPy array
data = [1, 2, 3, 4, 5]
arr = np.array(data)

# Performing operations on NumPy array
squared_arr = np.square(arr)
sum_of_squared = np.sum(squared_arr)

print("Original array:", arr)
print("Squared array:", squared_arr)
print("Sum of squared elements:", sum_of_squared)

2. Pandas

Developing a machine learning model and want to analyze the data given to you? Pandas is the answer to your problem. One of the most popular libraries used for data processing, Pandas allows you to read, edit, analyze, and also form new datasets in Python. Below is a basic example of reading data that contains the names, ages, and cities of people. We proceed to see the mean of the ages of the people in the dataset.

import pandas as pd

# Creating a Pandas DataFrame
data = {'Name': ['Alice', 'Bob', 'Charlie'],
        'Age': [25, 30, 35],
        'City': ['New York', 'San Francisco', 'Los Angeles']}

df = pd.DataFrame(data)

# Performing operations on Pandas DataFrame
average_age = df['Age'].mean()

print("DataFrame:")
print(df)
print("\nAverage Age:", average_age)

In my blog Pandas and Python: A Symphony of Data Analysis, I’ve demonstrated how to create new data using Python lists, save it, and load existing data in Python. Feel free to go ahead and skim through it.

3. Matplotlib

When it comes to graphs and illustrations, Matplotlib is the library you would want to use. Using the data that you may have or might have derived, Matplotlib allows you to put that data into beautiful diagrams that would enhance your presentations or your project report. Below is a simple script where we create a 2-D chart using the x- and y- axis, although this library also allows you to create a 3-D graph which however is not so trivial as this example below:

import matplotlib.pyplot as plt

# Creating a simple plot
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]

plt.plot(x, y)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Simple Plot using Matplotlib')
plt.show()

4. Pillow: Image Processing

Pillow is a beginner-friendly library for image processing tasks, enabling tasks like resizing, cropping, and enhancing images with ease.

from PIL import Image

# Opening and displaying an image using Pillow
image = Image.open('image.jpg')
image.show()

Pillow is a beginner-friendly library for image processing tasks, enabling tasks like resizing, cropping, and enhancing images with ease.

5. OpenCV: Computer Vision

Similar to Pillow, OpenCV is also a Python library image processing and computer vision applications, offering beginners powerful tools to work with images and videos.

Pillow is a Python library primarily designed for basic image processing and manipulation, focusing on tasks like opening, resizing, and saving images in various formats. It has a user-friendly interface and is suitable for simple image-related operations.

On the other hand, OpenCV is a comprehensive computer vision library with a broader scope, providing advanced functionalities for applications such as object detection, feature extraction, camera calibration, and even creating custom image filters like Snapchat filters. While Pillow is easier to use for basic image tasks and has fewer dependencies, OpenCV is more powerful and suitable for complex computer vision projects, making it a preferred choice for applications requiring in-depth image analysis and computer vision algorithms.

Below is an example code to convert an RGB image into grayscale using OpenCV:

import cv2

# Reading and displaying an image using OpenCV
image = cv2.imread('image.png')

# Converting the image to grayscale
grayscale = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

cv2.imshow('Grayscale Image', grayscale)
cv2.waitKey(0)
cv2.destroyAllWindows()

Conclusion

In this blog, we understood the 5 basic Python libraries that you should know as a Python beginner. You can go deeper and understand more functionalities of these libraries and create amazing applications like I did which is creating face filter using OpenCV.

Also, don’t for to check out PyBites Python Tips for quick and practical Python code snippets. In that book of about 200 pages, having a look at only 2 pages a day will take your Python skills to a much higher level within 100 days. Happy coding 😉

Any doubts regarding this blog or any other topics? Feel free to get in touch on my social media:

To enjoy such articles and more programming content, subscribe to my *FREE* monthly newsletter where you’ll be reminded of the posts that you might have missed:

Leave a Reply