Skip to content

About

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

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

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

ja 日本語はこちら

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

An introductory Python learning resource for students studying civil engineering, environmental engineering, and urban engineering.

This project is designed for 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 → Civil Engineering Applications

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


Table of Contents

  • target-audience
  • what-you-will-learn
  • articles-and-learning-materials
  • repository-structure
  • environment-setup
    • method-1-use-google-colab
    • method-2-use-uv--pycharm
  • dependencies
  • reproducibility-and-dependency-management
  • security-and-code-quality
  • running-python
  • about-jupyter-notebooks
  • python-in-civil-engineering
  • learning-python-in-the-age-of-ai
  • recommended-learning-path
  • recommended-environment
  • troubleshooting
  • for-developers
  • disclaimer
  • license
  • author
  • related-links
  • future-plans

Target Audience

This project is intended for:

  • Civil engineering students
  • Environmental engineering students
  • Urban 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

No advanced programming experience is required.


What You Will Learn

Through this project, you will learn the foundations required to use Python for engineering and data analysis.

The main topics include:

  • Setting up a Python development environment
  • Basic Python syntax and programming concepts
  • Data processing with pandas
  • Data visualization with Matplotlib
  • Numerical computing with NumPy
  • Scientific computing with SciPy
  • Working with Jupyter Notebooks
  • Managing Python environments and dependencies with uv
  • Applying Python to civil engineering problems
  • Understanding and verifying AI-generated Python code

Future materials will expand into civil engineering data analysis, GIS and spatial data, real-world public datasets, and more advanced numerical computation.


Articles and Learning Materials

The following materials are currently available.

Volume Topic GitHub Materials Qiita Article
Vol.1 Environment Setup Repository root https://qiita.com/skyblueao77/items/c4a0e7ddc9913c55994f
Vol.2 Python Basics ./qiita_02_basic/ https://qiita.com/skyblueao77/items/65abd5ad5befa474ee5f
Vol.3 pandas Introduction ./qiita_03_pandas/ https://qiita.com/skyblueao77/items/c8c4902706f97415d1ec
Vol.4 Matplotlib Introduction ./qiita_04_matplotlib/ https://qiita.com/skyblueao77/items/45da8225a78e99d28cc5
Vol.5 NumPy Introduction ./qiita_05_numpy/ https://qiita.com/skyblueao77/items/dfc9a12c147230814424
Vol.6 SciPy Introduction ./qiita_06_scipy/ https://qiita.com/skyblueao77/items/a1306b9cd6c06671191b
Vol.7 GeoPandas Introduction ./qiita_07_geopandas/ https://qiita.com/skyblueao77/items/3b64dff2020415332445

Each volume generally includes:

  • A Qiita article explaining the topic
  • A Jupyter Notebook for interactive learning
  • A Python script containing example code
  • A README with information specific to the volume

Repository Structure

The repository uses a common structure for each volume.

civil-engineering-python/
│
├── .github/
├── .gitignore
├── .python-version
├── .pre-commit-config.yaml
│
├── pyproject.toml
├── uv.lock
│
├── README.md
├── README_ja.md
├── LICENSE
├── SECURITY.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
│
├── qiita_XX_topic/
│   ├── README.md
│   ├── *.ipynb
│   └── *.py
│
└── ...

Each qiita_XX_topic/ directory generally corresponds to one volume of the Python for Civil Engineering series.

The Python environment is centrally managed at the project root using:

pyproject.toml
uv.lock
.python-version

The entire series shares one Python environment rather than creating a separate environment for every volume.


Environment Setup

This repository uses https://docs.astral.sh/uv/ to manage the Python environment and project dependencies.

The main environment consists of:

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

There are two main ways to use the learning materials.


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 without manually setting up a local Python environment.

You can upload or open the corresponding Jupyter Notebook and execute the code interactively.

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 Python on their computer
  • Want to run Jupyter Notebooks in a browser

Visit:

Google Colab


Method 2: Use uv + PyCharm

This method is recommended if you plan to study Python continuously or work with the repository locally.

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

uv can manage Python versions, virtual environments, and project dependencies.

1. Install PyCharm

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

https://www.jetbrains.com/pycharm

2. Install uv

Install uv according to the official documentation.

https://docs.astral.sh/uv/

After installation, check that uv is available:

uv --version

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

3. Clone the Repository

If Git is installed, clone the repository:

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

Move into the repository directory:

cd civil-engineering-python

4. Set Up the Python Environment

Run the following command from the project root:

uv sync

uv sync creates or updates the project environment 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

Run:

uv run python --version

The repository currently targets Python 3.13.

6. Start JupyterLab

From the project root, run:

uv run jupyter lab

Alternatively, you can open .ipynb files directly in an IDE that supports Jupyter Notebooks.

7. Open a Learning Material

Choose the directory corresponding to the volume you want to study.

For example:

qiita_03_pandas/
├── README.md
├── qiita_doboku_3.ipynb
└── qiita_doboku_3.py

You can read the README, execute the Notebook, and modify the example Python code while learning.


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

The exact dependencies and versions used by the project are defined and resolved through the files at the repository root.


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.

After cloning the repository, run:

uv sync

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

However, reproducibility does not guarantee that all dependencies are free of vulnerabilities. Users should keep their development tools and dependencies up to date and review relevant 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 GitHub security features to help maintain a well-managed development environment.

These include:

  • Security Policy: Instructions for reporting potential security vulnerabilities
  • Security Advisories: GitHub's mechanism for handling repository security advisories
  • Private Vulnerability Reporting: Private reporting of potential vulnerabilities when available
  • Dependabot Alerts: Monitoring dependencies for known vulnerabilities
  • Secret Scanning: Detection of certain accidentally committed secrets

Useful links:

Code Scanning

Automated code scanning can be added using CodeQL or another supported static analysis workflow.

If code scanning is configured, it can complement the existing dependency monitoring and development checks.

Pre-commit Checks

The repository uses pre-commit to automate development checks.

The configuration is stored in:

.pre-commit-config.yaml

The development workflow may include tools such as:

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

Developers can run all configured pre-commit checks manually:

uv run pre-commit run --all-files

These checks help identify formatting issues, syntax problems, unused code, 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

Python scripts can be executed from the project root using uv run.

For example:

uv run python qiita_03_pandas/qiita_doboku_3.py

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


About Jupyter Notebooks

This proect primarily provides interactivelearning materials in Jupyter Note*ook (.ipynb) format.

A Notebook allows you to learn through the following cycle:

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

This approach is particularly useful for programming beginners because code and results can be inspected step by step.

Do not worry if you do not understand everything immediately.

Experimenting with the examples and making small modifications is an important part of learning Python.


Python in Civil Engineering

Civil engineering involves working with many types of data.

Examples include:

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

Python can help support workflows such as:

Load data
    ↓
Organize and clean data
    ↓
Perform calculations
    ↓
Analyze data
    ↓
Visualize results
    ↓
Interpret the results

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

How can Python be used in civil engineering?

The long-term goal is to connect basic Python programming skills with practical engineering analysis.


Learning Python in the Age of AI

Generative AI can produce Python code relatively easily.

This raises a reasonable question:

Do I still need to learn Python if AI can generate code?

This project does not reject AI-assisted programming.

Instead, it emphasizes the ability to:

Understand, verify, and modify AI-generated code.

Even when AI generates code, engineers and students still need to consider questions such as:

  • What is being calculated?
  • Is the input data appropriate?
  • Are physical quantities and units handled correctly?
  • Why did an error occur?
  • Is the numerical method appropriate?
  • Is the calculated result reasonable?
  • Does the result make sense from a civil engineering perspective?

In engineering applications, successful code execution alone does not demonstrate that an analysis is correct.

Code runs successfully
        ≠
Engineering result is correct

Python knowledge therefore remains useful not only for writing programs, but also for understanding and evaluating code produced with AI assistance.

This project aims to develop both programming skills and the ability to critically verify computational results.


Recommended Learning Path

The recommended learning path is:

Environment Setup
        ↓
Python Basics
        ↓
Data Processing
     (pandas)
        ↓
Data Visualization
    (Matplotlib)
        ↓
Numerical Computing
  (NumPy and SciPy)
        ↓
Civil Engineering Data Analysis
        ↓
GIS and Spatial Data
        ↓
Advanced Engineering Applications

This learning path is intentionally independent of individual volume numbers.

As new materials are added to the series, they can be incorporated into the appropriate stage without continuously restructuring this README.

You do not need to understand everything immediately.

A useful learning cycle is:

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


Recommended Environment

This project primarily assumes the following environment:

Item Recommendation
OS Windows / macOS / Linux
Python 3.13
IDE PyCharm or another Python-compatible IDE
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 the project configuration files at the repository root.


Troubleshooting

uv Command Not Found

Check whether uv is available:

uv --version

If the command is not recognized, check the installation instructions in the official documentation:

https://docs.astral.sh/uv/


The Python Version Is Different

Check the Python version used by the project:

uv run python --version

The repository specifies its Python version using .python-version and project configuration at the repository root.


A Package Cannot Be Found

First, run:

uv sync

from the repository root.

Then check whether your IDE or Jupyter environment is using the Python environment associated with the project.


The Python Environment Cannot Be Selected in a Notebook

If the project environment does not appear as an available Jupyter kernel, you can register it manually.

From the project root, run:

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

Then restart Jupyter or your IDE and select:

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

Clone the repository:

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

Synchronize the project environment:

uv sync

Enable the configured Git hooks:

uv run pre-commit install

2. Automated Code Quality and Testing

When committing changes, the configured pre-commit hooks can automatically perform development checks.

The development workflow may include:

  • Ruff for static analysis and code quality
  • Pytest for automated testing
  • nbmake for executing and testing Jupyter Notebooks

Run all configured pre-commit checks manually:

uv run pre-commit run --all-files

Run tests:

uv run pytest --nbmake

Run Ruff:

uv run ruff check .

If you intentionally want Ruff to automatically fix supported issues:

uv run ruff check --fix .

Contributors should also read:

./CONTRIBUTING.md


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.

The examples in this repository should not be used without appropriate verification for professional engineering decisions.

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


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

Project

Python Environment and Development

Main Python Libraries


Future Plans

Future materials may cover topics such as:

  • Practical civil engineering data analysis
  • Analysis using real-world datasets
  • Publicly available civil engineering and infrastructure data
  • Data provided by organizations such as Japan's Ministry of Land, Infrastructure, Transport and Tourism (MLIT)
  • GIS and spatial data
  • GeoPandas
  • Statistical analysis
  • Numerical methods for engineering problems
  • Applications of Python in civil engineering
  • Python development with generative AI
  • Methods for verifying AI-generated code
  • Advanced numerical analysis

The long-term goal is to develop this repository into a practical learning resource that helps civil engineering students progress from learning basic Python to working with real-world civil engineering data and computational methods.


Contributing

Contributions, suggestions, and corrections are welcome.

If you find an error or have an idea for improving the learning materials, please open an Issue or follow the contribution guidelines in:

./CONTRIBUTING.md


Python for Civil Engineering

From learning Python basics to understanding and analyzing 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

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages