10 Essential Python Libraries Every Programmer Should Try

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