Python Data Analytics

Author: Fabio Nelli
File Type: pdf
Size: 8.9 MB
Language: English
Pages: 445

Python Data Analytics 3rd Edition: A Practical Engineering Guide to Pandas, NumPy, and Matplotlib

Introduction

Modern engineering increasingly depends on data. Whether the task involves monitoring machines, analysing energy consumption, evaluating structural measurements, studying production quality, or predicting operational trends, engineers must transform raw numbers into useful information.

Python Data Analytics: With Pandas, NumPy, and Matplotlib, 3rd Edition, written by Fabio Nelli and published by Apress in 2023, provides a broad introduction to Python-based data analysis. The third edition is listed as 445 pages and expands beyond the core NumPy, pandas, and Matplotlib workflow into areas such as machine learning, deep learning, social-media analysis, text analysis, and computer vision.

The central engineering idea is simple:

Raw data → Processing → Analysis → Visualization → Engineering decision ⚙️📊

ImagePython Data Analytics

Image

For students, the subject provides a practical bridge between programming and engineering mathematics. For professionals, it offers a repeatable way to automate analysis instead of relying entirely on spreadsheets and manual calculations.

The book’s contents move from data-analysis fundamentals and Python through NumPy, pandas, data input/output, manipulation, visualization, machine learning, deep learning, meteorological data, D3, handwritten-digit recognition, NLTK, and OpenCV.


Background Theory

Why engineers need data analytics

Engineering systems generate enormous quantities of measurements:

  • Temperature: (T)
  • Pressure: (P)
  • Force: (F)
  • Stress: (\sigma)
  • Strain: (\epsilon)
  • Voltage: (V)
  • Current: (I)
  • Flow rate: (Q)
  • Rotational speed: (\omega)
  • Energy consumption: (E)

A single sensor may produce thousands or millions of observations.

The challenge is not simply collecting these values. The real challenge is determining what they mean.

Suppose a temperature sensor produces:

[T = [72, 74, 75, 78, 91, 93, 94]]

An engineer could calculate:

[\bar{T}=\frac{1}{n}\sum_{i=1}^{n}T_i]

and determine the average temperature. But additional questions immediately appear:

  • Is the temperature increasing?
  • Was 94°C an abnormal measurement?
  • Is the sensor drifting?
  • Is the increase associated with machine load?
  • Should maintenance be scheduled?

This is where data analytics becomes an engineering discipline rather than simply a programming exercise.

The role of Python

Python provides an ecosystem in which mathematical computation, data manipulation, visualization, statistics, and machine learning can be combined.

Three important components are:

TechnologyPrimary roleEngineering value
NumPyNumerical arrays and mathematical operationsFast numerical computation
pandasData structures and data manipulationCleaning and analysing datasets
MatplotlibVisualizationCommunicating trends and relationships

The third edition places particular emphasis on pandas for data structures and manipulation while also covering NumPy and visualization with Matplotlib.


Definition

What is Python data analytics?

Python data analytics is the systematic use of Python programs, libraries, mathematical methods, and visualization techniques to collect, clean, transform, analyse, and interpret data.

A simplified mathematical representation is:

[D_{raw}\rightarrow D_{clean}\rightarrow D_{processed}\rightarrow I]

where:

  • (D_{raw}) = raw data
  • (D_{clean}) = validated and cleaned data
  • (D_{processed}) = transformed analytical data
  • (I) = engineering information or insight

NumPy

NumPy provides array-oriented numerical computing. Instead of treating every value as an isolated Python object, engineers can work with structured numerical arrays.

For example:

import numpy as np

temperature = np.array([72, 74, 75, 78, 91, 93])

print(np.mean(temperature))
print(np.max(temperature))
print(np.min(temperature))

This makes common operations concise and suitable for engineering calculations.

pandas

pandas provides high-level data structures such as Series and DataFrame.

A DataFrame can be imagined as an engineering test table:

TimeTemperaturePressureSpeed
0722.11200
1742.21250
2752.21300
3782.41350

The DataFrame makes it possible to filter, sort, group, aggregate, join, and transform such data.

Matplotlib

Matplotlib converts numerical results into visual information.

For engineers, a graph can reveal something that a table hides.

For example:

[y=f(x)]

may show whether a system is:

  • linear,
  • nonlinear,
  • stable,
  • oscillatory,
  • increasing,
  • decreasing,
  • or approaching a critical limit.

Step-by-Step Python Data Analytics Workflow

Step 1: Define the engineering problem

Never begin with code simply because a dataset exists.

First define the question.

For example:

Does increasing motor load significantly increase operating temperature?

This establishes the independent variable (x) and dependent variable (y):

[x = \text{Motor Load}]

[y = \text{Temperature}]

Step 2: Import the libraries

📊 import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

Each library has a distinct responsibility.

Step 3: Load the dataset

For a CSV file:

df = pd.read_csv("machine_data.csv")

Then inspect the structure:

print(df.head())
print(df.info())
print(df.describe())

This initial inspection is extremely important because analytical errors often originate from misunderstanding the dataset.

Step 4: Clean the data

Real engineering datasets are rarely perfect.

They may contain:

  • missing values,
  • duplicate records,
  • incorrect units,
  • impossible measurements,
  • sensor errors,
  • inconsistent timestamps.

A simple missing-value check is:

print(df.isnull().sum())

A duplicate check is:

print(df.duplicated().sum())

Step 5: Transform the data

Suppose power is calculated from voltage and current:

[P=VI]

Python can perform the transformation directly:

df["Power"] = df["Voltage"] * df["Current"]

Now the calculated engineering variable becomes part of the DataFrame.

Step 6: Calculate statistics

mean_temperature = df["Temperature"].mean()
maximum_temperature = df["Temperature"].max()
minimum_temperature = df["Temperature"].min()

These values can provide a first understanding of system behaviour.

Step 7: Visualize the results

plt.plot(df["Time"], df["Temperature"])
plt.xlabel("Time")
plt.ylabel("Temperature")
plt.title("Temperature vs Time")
plt.grid(True)
plt.show()

Image

ImageImage

Image

Step 8: Interpret the engineering meaning

The final step is not the graph.

The final step is the decision.

For example:

[T > T_{critical}]

could trigger an engineering inspection.

A successful analytics workflow therefore ends with an actionable conclusion rather than simply producing a chart.


Comparison: NumPy vs pandas vs Matplotlib

FeatureNumPypandasMatplotlib
Main purposeNumerical computationData manipulationVisualization
Main structurendarraySeries/DataFrameFigure/Axes
Best forArrays and mathematicsTabular dataCharts
FilteringBasicExcellentNot primary purpose
Statistical operationsStrongStrongLimited
Data import/exportLimitedExcellentNot primary purpose
Engineering graphsIndirectThrough plotting interfaceExcellent
Typical workflow positionComputePrepare/analyseCommunicate

How they work together

The three libraries should not be viewed as competitors.

They form a pipeline:

[\boxed{\text{NumPy} \leftrightarrow \text{pandas} \rightarrow \text{Matplotlib}}]

For example:

data = np.array([10, 20, 30, 40])

df = pd.DataFrame({
    "Measurement": data
})

df.plot()
plt.show()

The numerical array can become structured tabular information, which can then become a visualization.

Diagrams and Tables for the Engineering Workflow

The complete analytical pipeline

┌───────────────┐
│ Raw Data      │
│ Sensors/CSV   │
└───────┬───────┘
        ↓
┌───────────────┐
│ Data Cleaning │
│ pandas        │
└───────┬───────┘
        ↓
┌───────────────┐
│ Computation   │
│ NumPy         │
└───────┬───────┘
        ↓
┌───────────────┐
│ Visualization │
│ Matplotlib    │
└───────┬───────┘
        ↓
┌───────────────┐
│ Engineering   │
│ Decision      │
└───────────────┘

Image

Analytical method comparison

MethodQuestion answeredExample
MeanWhat is the typical value?Average temperature
MedianWhat is the central observation?Typical vibration
Standard deviationHow variable is the system?Pressure variation
CorrelationDo variables move together?Load vs temperature
VisualizationWhat pattern is visible?Temperature trend
GroupingHow do categories differ?Failure rate by machine
FilteringWhich observations matter?High-temperature events

ImageImage

Image

Image

 

Image


Examples

Example 1: Analysing manufacturing temperature

Imagine a production machine records temperature every minute.

import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv("temperature.csv")

df["Temperature"].describe()

plt.plot(df["Time"], df["Temperature"])
plt.xlabel("Time")
plt.ylabel("Temperature (°C)")
plt.title("Machine Temperature")
plt.show()

The engineer can then investigate periods where:

[T > T_{safe}]

Instead of manually searching thousands of readings, Python identifies the relevant region quickly.

Example 2: Electrical power analysis

Electrical power can be calculated as:

[P=VI]

For AC systems, depending on the system and measurement assumptions, apparent or real power may require additional quantities such as power factor.

A simplified dataset might contain voltage and current:

df["Power"] = df["Voltage"] * df["Current"]

The resulting power profile can then be plotted against time.

This approach is useful for identifying:

  • peak demand,
  • abnormal consumption,
  • equipment operating cycles,
  • unexpected load changes.

Example 3: Statistical engineering analysis

Suppose a component has measured dimensions:

dimensions = np.array([
    25.01, 24.98, 25.03, 25.00, 24.97
])

print(np.mean(dimensions))
print(np.std(dimensions))

The mean estimates the central dimension while standard deviation indicates variation.

That leads naturally toward quality-control analysis.

Real-World Applications

Manufacturing

Python analytics can process:

  • production measurements,
  • machine temperatures,
  • vibration signals,
  • cycle times,
  • defect records.

Engineers can compare production batches and identify process drift.

Civil and structural engineering

Data analysis can support monitoring of:

  • strain gauges,
  • displacement sensors,
  • structural vibration,
  • concrete testing,
  • environmental conditions.

A time-series graph can help engineers detect unusual changes before they become major problems.

Mechanical engineering

Mechanical systems produce large amounts of operational data.

Python can help analyse:

[F,\quad T,\quad \omega,\quad P,\quad a,\quad v]

where force, torque, angular velocity, power, acceleration, and velocity can be evaluated together.

Energy engineering

Energy datasets can contain thousands of hourly observations.

Engineers can calculate:

[E_{total}=\sum_{i=1}^{n}E_i]

and analyse consumption patterns across days, months, seasons, or operating conditions.

Environmental engineering

The book’s third edition includes a meteorological-data example, demonstrating how data analytics can be applied to environmental measurements.

Applications can include:

  • temperature,
  • rainfall,
  • wind speed,
  • humidity,
  • air-quality measurements.

Common Mistakes

Mistake 1: Analysing dirty data

Garbage in produces unreliable results:

[\text{Bad Input}\rightarrow\text{Bad Analysis}]

Always inspect missing values, duplicates, units, and extreme observations.

Mistake 2: Confusing correlation with causation

If:

[corr(X,Y)=0.9]

it does not automatically mean (X) causes (Y).

Two engineering variables may be influenced by a third variable.

Mistake 3: Ignoring units

Mixing:

[mm \quad \text{and} \quad m]

can produce an error factor of:

[1000]

Always document units.

Mistake 4: Creating misleading graphs

A poorly selected axis scale can exaggerate or hide trends.

Graphs should communicate engineering reality, not merely look attractive.

Mistake 5: Treating every outlier as an error

An outlier could be:

  1. a sensor failure,
  2. a data-entry mistake,
  3. a legitimate unusual event,
  4. an important engineering failure signal.

Never delete it automatically.


Challenges and Solutions

ChallengeEngineering solution
Large datasetsProcess data efficiently
Missing measurementsInvestigate and apply appropriate treatment
Noisy sensorsFiltering and statistical analysis
Different unitsStandardize units
OutliersInvestigate before removing
Complex relationshipsVisualization and statistical modelling
Repetitive analysisAutomate with Python scripts
Poor communicationUse clear engineering plots

One major advantage of a Python workflow is repeatability.

A spreadsheet analysis may require repeated manual actions. A Python script can perform the same procedure consistently:

[\text{Input}_1 \rightarrow \text{Script} \rightarrow \text{Result}_1]

[\text{Input}_2 \rightarrow \text{Script} \rightarrow \text{Result}_2]

This makes automation particularly valuable in professional engineering environments.


Case Study: Machine Temperature Monitoring

The engineering problem

Consider a manufacturing facility with a motor monitored every minute.

The engineering team wants to determine whether overheating occurs during periods of high load.

The dataset contains:

TimeLoad (%)Temperature (°C)
08:004052
08:105558
08:206564
08:307571
08:408579
08:509288

Analysis

The engineer imports the data:

df = pd.read_csv("motor.csv")

Then calculates correlation:

print(df["Load"].corr(df["Temperature"]))

A scatter plot can reveal whether temperature tends to increase with load.

plt.scatter(df["Load"], df["Temperature"])
plt.xlabel("Load (%)")
plt.ylabel("Temperature (°C)")
plt.title("Motor Load vs Temperature")
plt.show()

Engineering interpretation

If the relationship is strong and temperatures approach the equipment’s allowable operating range, the organization may investigate:

  • cooling performance,
  • lubrication,
  • bearing condition,
  • overload,
  • ventilation,
  • maintenance intervals.

The important point is that Python does not replace engineering judgment.

It amplifies engineering judgment by making large datasets easier to inspect.


Essential Tips

Build the fundamentals first

Before moving toward advanced machine learning, understand:

  • Python syntax,
  • arrays,
  • DataFrames,
  • indexing,
  • filtering,
  • grouping,
  • statistics,
  • visualization.

Think in engineering variables

Always identify:

[\text{Input} \rightarrow \text{System} \rightarrow \text{Output}]

This makes analytical problems easier to formulate.

Visualize before modelling

A simple graph can reveal:

  • outliers,
  • trends,
  • nonlinear behaviour,
  • clusters,
  • measurement errors.

Keep your analysis reproducible

Use scripts and notebooks rather than relying entirely on manual spreadsheet operations.

Learn progressively

A practical progression is:

Python
  ↓
NumPy
  ↓
pandas
  ↓
Matplotlib
  ↓
Statistics
  ↓
Machine Learning
  ↓
Advanced Engineering Analytics

FAQs

Is Python Data Analytics 3rd Edition suitable for beginners?

It can be useful for learners who already have some Python exposure. The book introduces data-analysis concepts and then progresses into NumPy, pandas, visualization, machine learning, and other topics. Its publisher listing characterizes it as intermediate to advanced, so complete Python beginners may benefit from learning basic Python first.

What are the main Python libraries covered?

The core title focuses on pandas, NumPy, and Matplotlib. The broader third edition also discusses technologies including scikit-learn, TensorFlow, D3, NLTK, and OpenCV.

Is pandas important for engineering data analysis?

Yes. pandas is particularly useful when engineering data is organized into rows and columns. It provides tools for reading, cleaning, filtering, grouping, transforming, and analysing structured datasets.

Why is NumPy important?

NumPy is designed for numerical computing and array-based operations. It is particularly useful when engineering calculations involve large numerical datasets or mathematical transformations.

Why should engineers learn Matplotlib?

Engineers frequently need to communicate technical behaviour visually. Matplotlib can produce line charts, scatter plots, bar charts, histograms, and other figures useful for exploring and presenting engineering data.

Can Python replace Excel in engineering analysis?

Not necessarily. Excel remains useful for many small and interactive calculations. Python becomes especially powerful when datasets are large, calculations are repetitive, workflows must be automated, or analysis needs to be reproduced consistently.

Does the third edition include machine learning?

Yes. The published contents include machine learning with scikit-learn and deep learning with TensorFlow, in addition to data-analysis fundamentals.

What engineering projects can I practise with Python?

Good beginner projects include:

  • temperature monitoring,
  • motor-load analysis,
  • energy-consumption analysis,
  • manufacturing quality control,
  • structural sensor analysis,
  • vibration analysis,
  • weather-data analysis,
  • equipment performance monitoring.

Conclusion

Python Data Analytics: With Pandas, NumPy, and Matplotlib, 3rd Edition provides a broad framework for understanding how Python can move engineering data from raw measurements to meaningful conclusions.

Its core strength is the relationship between three complementary technologies:

[\boxed{\text{NumPy}+\text{pandas}+\text{Matplotlib}}]

NumPy handles numerical computation. pandas organizes and manipulates structured data. Matplotlib turns analytical results into visual information.

But effective engineering analytics requires more than knowing library commands. The engineer must understand the physical system, validate measurements, select appropriate mathematical methods, respect units, investigate unusual observations, and interpret results within the correct technical context.

The third edition expands this foundation toward machine learning, deep learning, text processing, social-media analysis, and computer vision, making it broader than a simple introduction to pandas and plotting.

For students, the subject offers a powerful way to connect programming + mathematics + engineering. For professionals, it provides a foundation for building repeatable analytical workflows.

Ultimately, the goal of Python data analytics is not to produce more code or more charts.

It is to answer better engineering questions. ⚙️📈

Data → Evidence → Understanding → Decision → Better Engineering.

Unlock exclusive content
Enjoy all premium content by watching a short ad
Preparing ad...
BY ADX360