0% found this document useful (0 votes)
2 views13 pages

Python Scientific Libraries Guide

The document is a comprehensive guide to essential Python scientific libraries for data science, covering tools from numerical computing (NumPy) to deep learning (TensorFlow and PyTorch). It includes detailed sections on libraries like Pandas for data manipulation, Matplotlib for visualization, and Scikit-learn for machine learning, providing key concepts, essential code examples, and common operations. The guide is aimed at data science students, catering to users from beginner to advanced levels.

Uploaded by

ridawiam493
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views13 pages

Python Scientific Libraries Guide

The document is a comprehensive guide to essential Python scientific libraries for data science, covering tools from numerical computing (NumPy) to deep learning (TensorFlow and PyTorch). It includes detailed sections on libraries like Pandas for data manipulation, Matplotlib for visualization, and Scikit-learn for machine learning, providing key concepts, essential code examples, and common operations. The guide is aimed at data science students, catering to users from beginner to advanced levels.

Uploaded by

ridawiam493
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

NumPy Pandas Matplotlib Scikit-learn TensorFlow SciPy

Python Scientific Libraries


A Complete Guide for Data Science Students

Master the essential tools of modern data science — from numerical computing to machine
learning, visualization to deep learning.

■ 10 Libraries ■ Python 3.x ■ Beginner → Advanced


Python Scientific Libraries — Data Science Guide Page 2

Table of Contents
01 NumPy — Numerical Computing

02 Pandas — Data Manipulation

03 Matplotlib — Data Visualization

04 Seaborn — Statistical Visualization

05 SciPy — Scientific Computing

06 Scikit-learn — Machine Learning

07 Statsmodels — Statistical Modeling

08 TensorFlow & Keras — Deep Learning

09 PyTorch — Deep Learning Research

10 Plotly — Interactive Visualization

© 2024 Python Data Science Guide


Python Scientific Libraries — Data Science Guide Page 3

v1.26+
NumPy

The foundation of scientific Python — fast N-dimensional arrays

What is NumPy?
NumPy (Numerical Python) is the core library for numerical computation in Python. It provides a
high-performance multidimensional array object (ndarray) and tools for working with these arrays. Nearly
every scientific Python library — Pandas, Scikit-learn, TensorFlow — is built on top of NumPy arrays.

Core Concepts
• ndarray — The N-dimensional array, the backbone of NumPy.
• Broadcasting — Operations between arrays of different shapes.
• Vectorization — Apply functions element-wise without Python loops.
• Universal Functions (ufuncs) — Fast element-wise operations (sin, cos, exp…).

Essential Code Examples


import numpy as np # Create arrays a = [Link]([1, 2, 3, 4, 5]) b = [Link]((3, 4)) #
3x4 matrix of zeros c = [Link]((2, 3)) # 2x3 matrix of ones d = [Link](0, 10, 2) #
[0, 2, 4, 6, 8] e = [Link](0, 1, 5) # 5 evenly spaced values # Reshaping & indexing
matrix = [Link](12).reshape(3, 4) row = matrix[1, :] # second row col = matrix[:, 2]
# third column # Math operations (vectorized) result = [Link](a) + [Link](a + 1) dot =
[Link](matrix, matrix.T) # matrix multiplication # Statistics print([Link](), [Link](),
[Link](), [Link]())

Key Functions Reference


Function Description

[Link]() Create an ndarray from a list

[Link]() / [Link]() Arrays filled with 0s or 1s

[Link]() Evenly spaced values over an interval

[Link]() Change array shape without copying data

[Link]() Join arrays along an existing axis

[Link]() Matrix inverse

[Link]() Random samples from standard normal

[Link]() Conditional element selection

© 2024 Python Data Science Guide


Python Scientific Libraries — Data Science Guide Page 4

v2.x
Pandas

Powerful data structures for data analysis and manipulation

What is Pandas?
Pandas provides two key data structures: Series (1D labeled array) and DataFrame (2D labeled table). It
is the go-to tool for loading, cleaning, transforming, and analyzing structured datasets — think of it as a
supercharged spreadsheet inside Python.

Key Capabilities
• Read/write CSV, Excel, JSON, SQL, Parquet, and more
• Handle missing data with fillna(), dropna(), interpolate()
• Group, aggregate, and pivot data with groupby() and pivot_table()
• Merge and join multiple DataFrames like SQL
• Time-series resampling and rolling statistics

Essential Code Examples


import pandas as pd # Load data df = pd.read_csv("[Link]") # Exploration
print([Link]()) # first 5 rows print([Link]()) # dtypes & nulls print([Link]()) #
summary stats # Selection ages = df["age"] # single column (Series) subset = df[["name",
"age"]] # multiple columns young = df[df["age"] < 30] # boolean filter # Data
cleaning df["age"].fillna(df["age"].median(), inplace=True)
df.drop_duplicates(inplace=True) df["age"] = df["age"].astype(int) # GroupBy avg_salary
= [Link]("department")["salary"].mean() # Merge merged = [Link](df, other_df,
on="id", how="left") # Save df.to_csv("clean_data.csv", index=False)

Common Operations Cheatsheet


Operation Purpose

[Link] Rows and columns count

[Link]().sum() Count missing values per column

df.value_counts() Frequency count for a column

df.sort_values(by=col) Sort by column

[Link](func) Apply a function to each row/column

pd.get_dummies(df) One-hot encode categorical columns

df.pivot_table() Summarize data like an Excel pivot

[Link]('M') Resample time-series to monthly

© 2024 Python Data Science Guide


Python Scientific Libraries — Data Science Guide Page 5

v3.8+
Matplotlib

The original Python plotting library — publication-quality figures

What is Matplotlib?
Matplotlib is the foundational visualization library in Python. It gives you complete control over every
aspect of a figure — axes, ticks, labels, colors, and more. Most other visualization libraries (Seaborn,
Pandas plotting) are built on Matplotlib.

Key Plot Types


• Line plots, scatter plots, bar charts
• Histograms and density plots
• Box plots and violin plots
• Heatmaps and contour plots
• 3D surface and wireframe plots
• Subplots and multi-panel figures

Essential Code Examples


import [Link] as plt import numpy as np x = [Link](0, 2*[Link], 100) #
Object-oriented approach (recommended) fig, axes = [Link](1, 2, figsize=(12, 5)) #
Line plot axes[0].plot(x, [Link](x), label="sin(x)", color="steelblue", linewidth=2)
axes[0].plot(x, [Link](x), label="cos(x)", color="coral", linestyle="--")
axes[0].set_title("Trigonometric Functions") axes[0].set_xlabel("x") axes[0].legend()
axes[0].grid(alpha=0.3) # Histogram data = [Link](1000) axes[1].hist(data,
bins=30, color="steelblue", edgecolor="white", alpha=0.8) axes[1].set_title("Normal
Distribution") axes[1].set_xlabel("Value") plt.tight_layout() [Link]("[Link]",
dpi=150, bbox_inches="tight") [Link]()

© 2024 Python Data Science Guide


Python Scientific Libraries — Data Science Guide Page 6

v0.13+
Seaborn

Statistical data visualization built on Matplotlib

What is Seaborn?
Seaborn is a high-level statistical visualization library that integrates seamlessly with Pandas DataFrames.
It produces beautiful, informative plots with minimal code — ideal for exploratory data analysis (EDA).

Essential Code Examples


import seaborn as sns import [Link] as plt # Load a built-in dataset tips =
sns.load_dataset("tips") # Distribution plot [Link](data=tips, x="total_bill",
hue="sex", kde=True) [Link]() # Scatter with regression line [Link](data=tips,
x="total_bill", y="tip") [Link]() # Categorical plot [Link](data=tips, x="day",
y="total_bill", hue="smoker") [Link]() # Correlation heatmap corr =
tips.select_dtypes("number").corr() [Link](corr, annot=True, cmap="coolwarm",
center=0) [Link]() # Pair plot (multi-variable overview) [Link](tips, hue="sex")
[Link]()

Seaborn vs. Matplotlib at a Glance


Aspect Seaborn Matplotlib

Code Verbosity Low — sensible defaults High — full manual control

DataFrame Support Native integration Manual extraction needed

Statistical Plots Built-in (KDE, CI, etc.) Manual implementation

Customization Moderate (via Matplotlib API) Complete control

Best For EDA, quick insights Publication figures

© 2024 Python Data Science Guide


Python Scientific Libraries — Data Science Guide Page 7

v1.12+
SciPy

Scientific algorithms: optimization, integration, signal processing & more

What is SciPy?
SciPy extends NumPy with a collection of mathematical algorithms and convenience functions. It covers
optimization, integration, interpolation, linear algebra, signal processing, statistics, and more — essentially
a scientific calculator on steroids.

Major Submodules
Submodule Use Case

[Link] Statistical tests, distributions, descriptive statistics

[Link] Root finding, minimization, curve fitting

[Link] Linear algebra (faster than [Link])

[Link] Numerical integration (quadrature, ODEs)

[Link] Spline and polynomial interpolation

[Link] Signal processing, filtering, spectral analysis

[Link] Sparse matrix operations

[Link] Distance computations, KD-trees, convex hulls

Code Examples
from scipy import stats, optimize import numpy as np # Statistical test — t-test group_a
= [Link](50, 10, 100) group_b = [Link](55, 10, 100) t_stat, p_value
= stats.ttest_ind(group_a, group_b) print(f"p-value: {p_value:.4f}") # Curve fitting def
model(x, a, b): return a * [Link](-b * x) x_data = [Link](0, 4, 50) y_data =
model(x_data, 3, 1.5) + 0.1 * [Link](50) params, _ = optimize.curve_fit(model,
x_data, y_data) print(f"a={params[0]:.2f}, b={params[1]:.2f}") # Numerical integration
from [Link] import quad result, error = quad(lambda x: x**2, 0, 3) # integral
of x^2 from 0 to 3 print(f"Integral = {result:.4f}")

© 2024 Python Data Science Guide


Python Scientific Libraries — Data Science Guide Page 8

v1.4+
Scikit-learn

The #1 machine learning library — simple, efficient, consistent

What is Scikit-learn?
Scikit-learn (sklearn) is the industry-standard library for classical machine learning in Python. It provides a
consistent API for classification, regression, clustering, dimensionality reduction, model selection, and
preprocessing — all with clean, well-documented code.

The Estimator API Pattern


Every algorithm in sklearn follows the same pattern: fit(X, y) to train, predict(X) to infer, and
score(X, y) to evaluate. This consistency makes it easy to swap algorithms.

from sklearn.model_selection import train_test_split from [Link] import


StandardScaler from [Link] import RandomForestClassifier from [Link]
import classification_report from [Link] import Pipeline # 1. Load & split X,
y = load_your_data() X_train, X_test, y_train, y_test = train_test_split( X, y,
test_size=0.2, random_state=42 ) # 2. Build a pipeline (preprocessing + model) pipe =
Pipeline([ ("scaler", StandardScaler()), ("clf",
RandomForestClassifier(n_estimators=100, random_state=42)) ]) # 3. Train
[Link](X_train, y_train) # 4. Evaluate y_pred = [Link](X_test)
print(classification_report(y_test, y_pred)) # 5. Cross-validation from
sklearn.model_selection import cross_val_score scores = cross_val_score(pipe, X, y,
cv=5, scoring="f1_macro") print(f"CV F1: {[Link]():.3f} +/- {[Link]():.3f}")

Algorithm Quick Reference


Category Key Classes

Classification LogisticRegression, SVC, RandomForestClassifier, GradientBoostingClassifier

Regression LinearRegression, Ridge, Lasso, SVR, GradientBoostingRegressor

Clustering KMeans, DBSCAN, AgglomerativeClustering, GaussianMixture

Dimensionality PCA, TruncatedSVD, TSNE, UMAP (external)

Preprocessing StandardScaler, MinMaxScaler, LabelEncoder, OneHotEncoder

Model Selection GridSearchCV, RandomizedSearchCV, cross_val_score

© 2024 Python Data Science Guide


Python Scientific Libraries — Data Science Guide Page 9

v0.14+
Statsmodels

Statistical modeling, hypothesis testing & econometrics

What is Statsmodels?
Statsmodels complements Scikit-learn by focusing on statistical inference rather than prediction. It
provides detailed statistical output (p-values, confidence intervals, R-squared) similar to R — essential for
research and econometrics.
import [Link] as sm import pandas as pd # OLS Regression with full statistics
df = pd.read_csv("[Link]") X = sm.add_constant(df[["sqft", "bedrooms", "age"]]) y =
df["price"] model = [Link](y, X).fit() print([Link]()) # R^2, coefs, p-values,
CIs # Logistic regression logit = [Link](df["churn"], X).fit() print([Link]())
# ARIMA time series from [Link] import ARIMA arima =
ARIMA(df["sales"], order=(1, 1, 1)).fit() forecast = [Link](steps=12)

© 2024 Python Data Science Guide


Python Scientific Libraries — Data Science Guide Page 10

TF 2.x
TensorFlow & Keras

Google's deep learning framework — production-ready neural networks

What is TensorFlow / Keras?


TensorFlow is Google's open-source framework for large-scale machine learning and deep learning.
Keras is TensorFlow's high-level API (now integrated as [Link]) that lets you build neural networks in just
a few lines. TensorFlow is the preferred choice for production deployment and mobile/edge inference.
import tensorflow as tf from tensorflow import keras # Build a feedforward neural
network model = [Link]([ [Link](128, activation="relu",
input_shape=(20,)), [Link](0.3), [Link](64,
activation="relu"), [Link](1, activation="sigmoid") ]) [Link](
optimizer="adam", loss="binary_crossentropy", metrics=["accuracy"] ) # Train history =
[Link]( X_train, y_train, epochs=50, batch_size=32, validation_split=0.2,
callbacks=[[Link](patience=5)] ) # Evaluate loss, acc =
[Link](X_test, y_test) print(f"Test Accuracy: {acc:.4f}") # Save & load
[Link]("[Link]") loaded = [Link].load_model("[Link]")

Core Layer Types


Layer Purpose

Dense Fully connected layer — the basic building block

Conv2D 2D convolution for image processing (CNNs)

LSTM / GRU Recurrent layers for sequences and time series

Embedding Map integer indices to dense vectors (NLP)

BatchNorm Normalize activations for faster training

Dropout Randomly zero activations — regularization

© 2024 Python Data Science Guide


Python Scientific Libraries — Data Science Guide Page 11

v2.x
PyTorch

Facebook's dynamic deep learning framework — research & flexibility

What is PyTorch?
PyTorch is Meta's open-source deep learning framework, known for its dynamic computation graph
('define-by-run') which makes debugging and research much easier than static-graph frameworks. It
dominates academic research and is increasingly used in production via TorchScript.
import torch import [Link] as nn import [Link] as optim # Define a model using
[Link] class MLP([Link]): def __init__(self): super().__init__() [Link] =
[Link]( [Link](20, 128), [Link](), [Link](0.3), [Link](128, 64),
[Link](), [Link](64, 1), [Link]() ) def forward(self, x): return [Link](x)
model = MLP() criterion = [Link]() optimizer = [Link]([Link](),
lr=1e-3) # Training loop for epoch in range(50): [Link]() optimizer.zero_grad()
outputs = model(X_train) loss = criterion(outputs, y_train) [Link]()
[Link]() # Inference [Link]() with torch.no_grad(): preds = model(X_test)

PyTorch vs TensorFlow/Keras
Aspect PyTorch TensorFlow/Keras

Graph Type Dynamic (eager by default) Static (with [Link])

Debugging Standard Python debugger [Link] / more complex

Community Dominant in research Dominant in production

Deployment TorchScript / ONNX TensorFlow Serving / TFLite

Learning Curve Moderate Low with Keras API

© 2024 Python Data Science Guide


Python Scientific Libraries — Data Science Guide Page 12

v5.x
Plotly

Interactive, web-ready visualizations and dashboards

What is Plotly?
Plotly creates interactive, publication-quality charts that can be embedded in web applications. Unlike
Matplotlib, Plotly charts are HTML/JavaScript-based, allowing users to zoom, pan, hover for tooltips, and
filter data. The Plotly Express API offers a concise, high-level interface for the most common plot types.
import [Link] as px import plotly.graph_objects as go df = [Link]() #
Animated scatter plot fig = [Link]( df, x="gdpPercap", y="lifeExp", size="pop",
color="continent", hover_name="country", log_x=True, animation_frame="year",
size_max=55, title="Life Expectancy vs GDP per Capita" ) [Link]() # Interactive bar
chart df_2007 = df[[Link] == 2007] fig2 = [Link](df_2007, x="continent", y="lifeExp",
color="continent", barmode="group") [Link]() # Save as HTML
fig.write_html("[Link]") fig.write_image("[Link]") # requires kaleido

Plotly Ecosystem
Component Purpose

Plotly Express (px) High-level, one-liner charts from DataFrames

Plotly Graph Objects Low-level, fully customizable chart construction

Dash Build interactive analytical web apps in pure Python

Plotly Chart Studio Online sharing and collaboration platform

© 2024 Python Data Science Guide


Python Scientific Libraries — Data Science Guide Page 13

Ecosystem Overview & Learning Path

When to Use Each Library


Library Primary Use Case

NumPy Numerical arrays, linear algebra, low-level math

Pandas Tabular data — loading, cleaning, transforming

Matplotlib Static publication-quality plots with full control

Seaborn Fast statistical EDA with beautiful defaults

SciPy Scientific algorithms (stats tests, optimization, ODEs)

Scikit-learn Classical ML: classification, regression, clustering

Statsmodels Statistical inference, p-values, econometrics

TensorFlow Deep learning: production, mobile, large-scale

PyTorch Deep learning: research, NLP, computer vision

Plotly Interactive charts, dashboards, and web apps

Recommended Learning Path


Step 1 — Foundation Python basics → NumPy → Pandas

Step 2 — Visualization Matplotlib → Seaborn → Plotly

Step 3 — Classical ML SciPy (stats) → Scikit-learn

Step 4 — Deep Learning TensorFlow/Keras (start) → PyTorch (research)

Step 5 — Specialize NLP (HuggingFace), CV (torchvision), Time-series…

Keep experimenting, keep building — data science mastery comes through practice!

© 2024 Python Data Science Guide

You might also like