close
Skip to content

Repository files navigation

Python for Civil Engineering (土木のためのPython入門)

🇯🇵 日本語はこちら

License: MIT Python Version Managed by uv Security Policy Dependabot Secret Scanning Open In Colab

土木工学・環境工学・都市工学分野を学ぶ学生のための Python 入門用学習教材リポジトリです。

本プロジェクトは、これから Python の学習を始める土木専攻の学生を対象としています。以下のステップに沿って、土木分野における Python 活用の基礎を網羅的に学べるよう構成されています。

環境構築 → Python の基礎 → データ処理 → 可視化 → 数値計算

本リポジトリは、Qiita に連載中の解説記事、Jupyter Notebook、および Python スクリプトと連動して学習を進められるよう設計されています。 🇯🇵 日本語はこちらから

A Python introductory learning resource for students studying civil engineering.

This project is designed for civil engineering students who are beginning to learn Python. It covers the fundamentals of using Python in civil engineering through the following progression:

Environment Setup → Python Basics → Data Processing → Visualization → Numerical Computing

The repository is designed to be used together with the accompanying Qiita articles, Jupyter Notebooks, and Python code.


Table of Contents


Target Audience

This project is intended for:

  • Civil engineering students
  • Students who are beginning to learn Python
  • Programming beginners
  • Students who want to perform data analysis in civil engineering
  • Students who want to learn NumPy, pandas, Matplotlib, and SciPy
  • Students who want to understand and verify Python code generated by AI
  • Students who are unsure how Python can be applied to civil engineering

What You Will Learn

The following content is currently available:

Volume Content Main Topics
Vol.1 Environment Setup Google Colab / uv / PyCharm / Python
Vol.2 Python Basics Variables / Data Types / Conditional Statements / Loops / Lists
Vol.3 pandas Introduction DataFrame / Series / Data Extraction / CSV / Basic Statistics
Vol.4 Matplotlib Introduction Line Plots / Scatter Plots / Axes / Labels / Legends / Saving Figures
Vol.5 NumPy Introduction ndarray / Array Operations / Vectorization / Numerical Computing
Vol.6 SciPy Introduction Interpolation / Numerical Integration / Numerical Differentiation / Scientific Computing

Future topics will include civil engineering data analysis, GIS and spatial data, analysis using real-world datasets, and numerical computation.


Articles

Vol.1 Environment Setup

Python for Civil Engineering Vol.1: Environment Setup (Google Colab and uv)

This article covers how to prepare a Python environment for learning.

Topics include:

  • Google Colab
  • PyCharm
  • uv
  • Python
  • Virtual environments

Qiita Article: Vol.1 Environment Setup


Vol.2 Python Basics

Python for Civil Engineering Vol.2: Python Basics

This article covers the fundamental Python syntax required to use Python.

Topics include:

  • Variables
  • Data types
  • Arithmetic operations
  • Conditional statements
  • Loops
  • Lists

Examples are designed with civil engineering applications in mind.

Qiita Article: Vol.2 Python Basics


Vol.3 pandas Introduction

Python for Civil Engineering Vol.3: Introduction to pandas

This article covers how to process tabular data commonly used in civil engineering with pandas.

Topics include:

  • DataFrame
  • Series
  • Creating data
  • Selecting rows and columns
  • Conditional filtering
  • Basic statistical processing
  • Reading CSV files

Qiita Article: Vol.3 Introduction to pandas


Vol.4 Matplotlib Introduction

Python for Civil Engineering Vol.4: Introduction to Matplotlib

This article covers how to visualize civil engineering data organized with pandas and other tools using Matplotlib.

Topics include:

  • Line plots
  • Scatter plots
  • Axis labels, titles, and legends
  • Japanese text display
  • Saving figures

Qiita Article: Vol.4 Introduction to Matplotlib


Vol.5 NumPy Introduction

Python for Civil Engineering Vol.5: Introduction to NumPy

This article introduces NumPy as a foundation for numerical computing in civil engineering.

Topics include:

  • ndarray
  • Creating arrays
  • Array shapes
  • Indexing and slicing
  • Array operations
  • Vectorization
  • Basic numerical computation

Qiita Article: Vol.5 Introduction to NumPy — Arrays, Matrices, and Numerical Computing


Vol.6 SciPy Introduction

Python for Civil Engineering Vol.6: Introduction to SciPy

This article introduces SciPy for more advanced scientific and numerical computing based on NumPy.

Topics include:

  • Interpolation
  • Numerical integration
  • Numerical differentiation
  • Scientific computing
  • Choosing between NumPy and SciPy

Qiita Article: Vol.6 SciPy for Scientific Computing — Interpolation, Numerical Integration, Numerical Differentiation, and Optimization


Repository Structure

This repository uses one Python environment for the entire project.

civil-engineering-python/
│
├── .gitignore
├── .python-version
├── pyproject.toml
├── uv.lock
├── README.md
├── README_ja.md
├── LICENSE
├── SECURITY.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── .pre-commit-config.yaml
│
├── qiita_02_basic/
│   ├── README.md
│   ├── civil_engineering_python_intro_02.ipynb
│   └── qiita_doboku_2.py
│
├── qiita_03_pandas/
│   ├── README.md
│   ├── qiita_doboku_3.ipynb
│   └── qiita_doboku_3.py
│
├── qiita_04_matplotlib/
│   ├── README.md
│   ├── qiita_doboku_4.ipynb
│   └── qiita_doboku_4.py
│
├── qiita_05_numpy/
│   ├── README.md
│   ├── qiita_doboku_5.ipynb
│   └── qiita_doboku_5.py
│
└── qiita_06_scipy/
    ├── README.md
    ├── qiita_doboku_6.ipynb
    └── qiita_doboku_6.py

Python environment settings are centrally managed at the project root.

pyproject.toml
uv.lock
.python-version

Each volume directory generally contains the Notebook, Python code, and README corresponding to that volume.


Environment Setup

This repository uses uv to manage the Python environment.

The main environment consists of:

  • Python 3.13
  • uv
  • Jupyter
  • ipykernel
  • PyCharm
  • NumPy
  • pandas
  • Matplotlib
  • SciPy

If you want to try the materials without setting up a local environment, you can also use Google Colab.


Method 1: Use Google Colab

This method is recommended if you simply want to try Python first.

Google Colab allows you to execute Python code directly in a web browser.

Open the Notebook using the "Open in Colab" button provided in each article.

With Google Colab, you generally do not need to install Python or Jupyter manually.

Google Colab is recommended for people who:

  • Want to try Python first
  • Want to learn without setting up a local environment
  • Do not want to install a Python environment on their computer
  • Want to run Notebooks in a browser

Method 2: Use uv + PyCharm

This method is recommended if you plan to study Python continuously.

This project manages the Python environment for the entire repository using uv.

uv is a tool that can manage Python versions, virtual environments, and packages.

1. Install PyCharm

If you want to use PyCharm, install it from the official website.

PyCharm Official Website

2. Install uv

Install uv according to the official documentation.

uv Official Documentation

On Windows PowerShell, you can use the official installation method.

After installation, run:

uv --version

If a version number is displayed, uv has been installed successfully.

3. Clone the Repository

If Git is installed, clone the repository using:

git clone https://github.com/skyblueao77/civil-engineering-python.git

Then move into the repository directory:

cd civil-engineering-python

4. Set Up the Python Environment

Run the following command from the project root directory:

uv sync

uv sync prepares the Python environment and dependencies based on pyproject.toml and uv.lock.

This repository does not create a separate Python environment for each volume. The entire series shares one Python environment.

5. Check the Python Version

uv run python --version

If Python 3.13 is displayed, the basic environment setup is complete.

6. Start Jupyter

From the project root, run:

uv run jupyter lab

Alternatively, you can open .ipynb files directly in PyCharm and execute the Notebook there.

7. Open a Notebook

For example, for Vol.2:

qiita_02_basic/
└── civil_engineering_python_intro_02.ipynb

For Vol.3:

qiita_03_pandas/
└── qiita_doboku_3.ipynb

Use the corresponding Notebook for each volume.


About uv sync

This repository manages the Python environment and dependencies at the project root.

civil-engineering-python/
├── pyproject.toml
├── uv.lock
└── .python-version

Therefore, you should generally run:

uv sync

from the repository root.

The uv.lock file records specific dependency versions, making it easier to reproduce the project environment across different machines.


Dependencies

The main dependencies currently include:

Package Purpose
NumPy Numerical computing and array processing
pandas Tabular data processing
Matplotlib Data visualization
SciPy Scientific computing
Jupyter Notebook environment
ipykernel Python kernel

Dependencies are managed in the root pyproject.toml.


Reproducibility and Dependency Management

Reproducibility is important when sharing educational code and numerical computing environments.

This repository uses the following files to manage the Python environment:

File Purpose
pyproject.toml Defines the project and its dependencies
uv.lock Records resolved dependency versions
.python-version Specifies the Python version used by the project

The project uses a single environment at the repository root rather than maintaining a separate environment for each volume.

When setting up the project, run:

uv sync

This allows uv to create or update the project environment based on the project's configuration and lock file.

Using a lock file also helps reduce unintended differences in dependency versions between development environments.

However, a lock file alone does not guarantee complete security. Users should still keep development tools and dependencies up to date and review security advisories when appropriate.


Security and Code Quality

Security, dependency management, reproducibility, and code quality are treated as part of the repository's development process.

GitHub Security Features

The repository uses several GitHub security features to help maintain a secure and well-maintained development environment.

Currently enabled features include:

  • Security Policy — Provides instructions for securely reporting potential vulnerabilities.
  • Security Advisories — Provides a mechanism for managing and disclosing security advisories.
  • Private Vulnerability Reporting — Allows potential vulnerabilities to be reported privately.
  • Dependabot Alerts — Monitors project dependencies for known vulnerabilities.
  • Secret Scanning — Helps detect accidentally committed secrets.

View Security Policy

View Security Advisories

View Dependabot Alerts

View Secret Scanning

Code Scanning

GitHub Code Scanning is planned for this repository but is currently not configured.

When CodeQL or another supported code scanning workflow is configured, automated static security analysis can be added to the repository's security workflow.

Dependency Management

Project dependencies are centrally managed through:

pyproject.toml
uv.lock
.python-version

The uv.lock file records resolved dependency versions to improve reproducibility and reduce unexpected dependency changes.

Dependabot Alerts provide an additional layer of monitoring for known vulnerabilities in project dependencies.

Pre-commit Checks

The repository uses pre-commit to run automated checks before commits.

The configuration is stored in:

.pre-commit-config.yaml

The development workflow includes:

  • Ruff — Static analysis, formatting, and code quality checks
  • Pytest — Automated testing
  • nbmake — Execution-based testing of Jupyter Notebooks

Developers can run the checks manually with:

uv run pre-commit run --all-files

These checks help detect syntax errors, unused variables, formatting issues, and problems that prevent Python scripts or Jupyter Notebooks from executing correctly.

Security Scope

This is an educational repository, not a security-critical production system.

The security features and development checks described above are intended to improve repository hygiene, dependency monitoring, reproducibility, and code quality.

They should not be interpreted as a guarantee that the repository or every dependency is completely free of vulnerabilities.


Running Python

To run a Python file, execute a command such as the following from the project root:

uv run python qiita_03_pandas/qiita_doboku_3.py

Using uv run ensures that the Python environment managed by the project is used.


About Jupyter Notebooks

This project primarily provides code in Jupyter Notebook (.ipynb) format.

With a Notebook, you can learn through the following cycle:

Write code
    ↓
Run it
    ↓
Check the result
    ↓
Modify the code
    ↓
Run it again

This format is suitable for beginners who want to learn by actually running Python code.


Python in Civil Engineering

Civil engineering involves working with many types of data.

For example:

  • Rainfall
  • Water levels
  • River discharge
  • Traffic volume
  • Terrain data
  • Surveying data
  • Geotechnical data
  • Structural monitoring data
  • Experimental data

Python can help streamline the following workflow:

Load data
    ↓
Organize data
    ↓
Perform calculations and statistical processing
    ↓
Visualize data
    ↓
Analyze results

This project focuses not only on learning Python syntax, but also on understanding:

"How can Python be used in civil engineering?"


Learning Python in the Age of AI

Today, generative AI can generate Python code relatively easily.

This raises a reasonable question:

"Do I still need to learn how to write Python code myself?"

This project does not reject AI-assisted code generation. Instead, it emphasizes the ability to:

understand, verify, and modify code generated by AI.

For example, even when asking AI to generate code, you still need to determine:

  • What is being calculated?
  • Is the input data correct?
  • Are the units correct?
  • What is causing an error?
  • Is the calculated result reasonable?
  • Does the result make sense from a civil engineering perspective?

In particular, in civil engineering,

"The program executed successfully" does not mean "the analysis result is correct."

In addition to Python knowledge, it is important to develop the ability to verify results from a civil engineering perspective.


Recommended Learning Path

The recommended learning sequence is:

Vol.1
Environment Setup
    ↓
Vol.2
Python Basics
    ↓
Vol.3
pandas
    ↓
Vol.4
Matplotlib
    ↓
Vol.5
NumPy
    ↓
Vol.6
SciPy
    ↓
Civil Engineering Data Analysis
    ↓
GIS and Spatial Data
    ↓
Advanced Numerical Computing and Analysis

You do not need to understand everything immediately.

Run the Notebooks while learning and repeat the following cycle:

"Write code → Run it → Check the result → Make a small modification"


Recommended Environment

This project primarily assumes the following environment:

Item Recommendation
OS Windows / macOS / Linux
Python 3.13
IDE PyCharm
Python Environment Manager uv
Notebook Jupyter Notebook / JupyterLab
Browser-based Execution Google Colab
Version Control Git / GitHub

Python and package versions are managed according to pyproject.toml and uv.lock in the repository.


Troubleshooting

uv Command Not Found

Run:

uv --version

If an error occurs, check whether uv has been installed correctly.

uv Official Documentation


The Python Version Is Different

Check the version with:

uv run python --version

This repository specifies the Python version in the .python-version file at the project root.


A Package Cannot Be Found

First, run:

uv sync

from the project root.

Then check whether PyCharm or Jupyter is using the Python environment managed by the project.


The Python Environment Cannot Be Selected in a Notebook

Open the Notebook in PyCharm or Jupyter and check whether the selected Python interpreter is the project's environment.

If necessary, run the following from the project root:

uv run python -m ipykernel install --user --name civil-engineering-python --display-name "Python (civil-engineering-python)"

For Developers

This repository uses uv for Python environment and dependency management, and pre-commit for automated development checks.

1. Developer Environment Setup

After cloning the repository, run the following commands to install dependencies and enable Git Hooks for automatic checks:

# Synchronize dependencies
uv sync

# Enable Git Hooks
uv run pre-commit install

2. Automated Code Quality & Testing

When executing git commit, the configured checks run automatically on the local machine.

The development workflow includes:

  • Ruff: Static code analysis, formatting, and detection of syntax issues or unused variables.
  • Pytest (+ nbmake): Verification and execution tests for Python scripts and Jupyter Notebook (.ipynb) cells.

Running Tests Manually

To manually verify the repository before committing, run:

# Run pre-commit checks on all files
uv run pre-commit run --all-files

# Run Pytest with Jupyter Notebook execution
uv run pytest --nbmake

# Run Ruff
uv run ruff check --fix

Disclaimer

This repository is an educational resource for learning Python and its applications in civil engineering.

The accuracy, completeness, or reliability of the code and explanations provided in this repository is not guaranteed.

In particular, when using calculations related to civil engineering for actual practice, design, construction, or safety-related decisions, always consult qualified professionals and verify the results against official documents, standards, guidelines, and applicable regulations.


License

This repository is released under the MIT License.

See the LICENSE file for details.


Author

skyblueao77

A civil engineering student learning Python, data analysis, AI, and related technologies.

The "Python for Civil Engineering" series is also published on Qiita.


Related Links


Future Plans

The following topics are planned for future releases:

  • Practical civil engineering data analysis
  • Numerical computing with NumPy and SciPy
  • Using publicly available data from organizations such as the Ministry of Land, Infrastructure, Transport and Tourism (MLIT)
  • GIS and GeoPandas
  • Applications of Python in civil engineering
  • Analysis using real-world datasets
  • Python development with generative AI
  • Methods for verifying AI-generated code
  • Advanced numerical analysis in civil engineering

The goal is to develop this repository into a practical learning resource that helps civil engineering students progress from learning Python to actually working with real-world civil engineering data.

About

Python for Civil Engineering — 土木・環境・都市工学分野でPythonを活用するための実践的な入門教材。NumPy・pandas・Matplotlib・SciPy・GeoPandasなどを用いて、データ分析・可視化・数値計算・GISを学びます。

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages