NumPy: The Foundation of Numerical Computing
NumPy (Numerical Python) is used for scientific computing in Python. It provides powerful N-dimensional array objects and tools for working with these arrays. This makes it faster and more efficient than using standard Python lists for numerical operations.
import numpy as np
= np.array([1, 2, 3, 4, 5])
arr
print(arr + 2) # Add 2 to each element
print(arr * 2) # Multiply each element by 2
print(np.mean(arr)) # Calculate the mean
print(np.std(arr)) # Calculate the standard deviation
= np.array([[1, 2], [3, 4]])
arr2d print(arr2d.shape) #Get the shape of the array
print(arr2d.transpose()) #transpose the array
Pandas: Data Wrangling Made Easy
Pandas is a library for data manipulation and analysis. It introduces the DataFrame
object, a powerful structure for representing tabular data, similar to a spreadsheet or SQL table.
import pandas as pd
= {'Name': ['Alice', 'Bob', 'Charlie'],
data 'Age': [25, 30, 28],
'City': ['New York', 'London', 'Paris']}
= pd.DataFrame(data)
df
print(df)
print(df['Name'])
print(df[df['Age'] > 28])
print(df.groupby('City')['Age'].mean())
Matplotlib: Visualizing Your Data
Matplotlib is the go-to library for creating static, interactive, and animated visualizations in Python. It offers a wide range of plot types to effectively represent your data.
import matplotlib.pyplot as plt
= [1, 2, 3, 4, 5]
x = [2, 4, 1, 3, 5]
y
plt.plot(x, y)"X-axis")
plt.xlabel("Y-axis")
plt.ylabel("Line Plot")
plt.title(
plt.show()
plt.scatter(x, y)"X-axis")
plt.xlabel("Y-axis")
plt.ylabel("Scatter Plot")
plt.title( plt.show()
Scikit-learn: Machine Learning for Everyone
Scikit-learn provides a set of tools for various machine learning tasks, including classification, regression, clustering, dimensionality reduction, and model selection.
from sklearn.linear_model import LinearRegression
import numpy as np
= np.array([[1], [2], [3]])
X = np.array([2, 4, 5])
y
= LinearRegression()
model
model.fit(X, y)
print(model.predict([[4]]))
Requests: Simplifying HTTP Requests
The requests
library makes interacting with web APIs incredibly easy. It handles the complexities of making HTTP requests, allowing you to focus on retrieving and processing data.
import requests
= requests.get("https://www.example.com")
response
print(response.status_code)
print(response.text)
These are just a few of the many powerful Python packages available. Exploring and mastering these tools will improve your Python programming capabilities and open up a world of possibilities.