10 Essential Python Libraries Every Programmer Should Try

10 Essential Python Libraries
Content
pip install numpy
import numpy as np
Create a NumPy array
arr = np.array([1, 2, 3, 4, 5])
Perform basic arithmetic operations
print(arr + 5) # [ 6 7 8 9 10]
print(arr * 2) # [ 2 4 6 8 10]
Calculate the mean of the array
mean = np.mean(arr)
print(mean) # 3.0
pip install pandas
import pandas as pd
Create a DataFrame
data = {‘Name’: [‘John’, ‘Jane’, ‘Bob’], ‘Age’: [28, 24, 22]}
df = pd.DataFrame(data)
Perform operations on the DataFrame
mean_age = df[‘Age’].mean()
pip install matplotlib
import matplotlib.pyplot as plt
Plot a simple line graph
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
plt.plot(x, y)
plt.show()
pip install scikit-learn
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
X, y = … # Load or create your dataset
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
model = LogisticRegression()
model.fit(X_train, y_train)
pip install tensorflow
import tensorflow as tf
Create a simple neural network
model = tf.keras.Sequential([
tf.keras.layers.Dense(10, activation=’relu’, input_shape=(784,)),
tf.keras.layers.Dense(1, activation=’sigmoid’)
])
pip install Flask
from flask import Flask
app = Flask(name)
@app.route(‘/’)
def hello_world():
return ‘Hello, World!’
if name == ‘main‘:
app.run()
python app.py
pip install requests
import requests
Send a GET request
response = requests.get(‘https://www.example.com’)
print(response.text)
pip install beautifulsoup4
from bs4 import BeautifulSoup
import requests
Example of using Beautiful Soup to scrape data from a webpage
url = ‘https://www.example.com’
response = requests.get(url)
soup = BeautifulSoup(response.text, ‘html.parser’)
pip install sqlalchemy
from sqlalchemy import create_engine, Column, Integer, String, Sequence
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
Define a basic SQLAlchemy model, create an SQLite in-memory database, and generate tables
Base = declarative_base()
engine = create_engine(‘sqlite:///:memory:’)
Base.metadata.create_all(engine)
pip install pytest
Example Pytest test function
def test_addition():
result = add(2, 3)
assert result == 5
pytest

So this was the list of Python libraries

Ready to automate your business process?

Abdul Hannan

Abdul Hannan

AI Business Strategist

Iqra Shafqat

Iqra Shafqat

AI Engineer
Share

Suggested Articles

Unlock 10x Business Growth with AI-Powered Solutions

From ideation to deployment—get your AI solution live in just 6 weeks. No tech headaches.

WhatsApp