Python Vibe Coding Course — Part 1
Introduction
Why Python? What is environment setup?
Python is the de facto standard language for research data analysis. It is free to use and gives you access to the many libraries that researchers around the world share. This course covers everything from setting up a Python environment, to coding with the help of an LLM (large language model), to publishing reproducible analyses alongside your papers, step by step for beginners. Part 1 starts with the foundational concepts. You will learn what Python is, what environment setup means, why you should build your environment locally, and why reproducibility matters.
Why use Python?
There are many tools for research data analysis, such as R, MATLAB, and SAS. Python stands out for three key reasons.
- Free and open to everyone. It is open-source (publicly available source code, free for anyone to use) and does not depend on commercial licenses or institutional subscriptions.
- Increasingly the standard across research fields. Python-based tools are available for almost every research field, including machine learning, image analysis, statistics, and geospatial analysis. The code that authors publish so others can reproduce a paper's results is often written in Python, too.
- The language LLMs excel at. Because Python is open-source, enormous amounts of code, tutorials, and Q&A posts are publicly available. LLMs such as ChatGPT and Claude have learned from large amounts of this material, so they tend to generate more accurate code in Python than in other languages.
Python is also designed to be readable. Its syntax is close to plain English, which makes it an excellent entry point for programming beginners.
What does "writing and running code" mean?
The general flow of data analysis in Python looks like this.
- Write Python instructions (code) in a code editor
- Pass that code to the Python interpreter, the "execution engine"
- The interpreter reads the instructions line by line and performs calculations, reads files, draws charts, and so on
- Results are displayed on screen or saved as files
Think of it like writing a formula in an Excel cell to get a result. The difference is that Python lets you write the whole procedure, not just a formula. For example, "read all CSVs in a folder, compute the mean, plot a chart, and save it as an image" can all be written as a reusable, repeatable script.
This is what enables reproducibility. Manual steps done in Excel are hard to recall later, but Python code is the procedure itself, so it serves as its own documentation.
What is a code editor? (VSCode)
A code editor is a dedicated application for writing code. While you could write code in Notepad or Word, a code editor offers handy features like the ones below.
- Syntax highlighting (instructions and strings shown in different colors for readability)
- Autocomplete (suggests completions as you type)
- Highlighting of error locations
- A terminal (a panel for typing commands) in the same window
- Extensions that add more features
This course uses VSCode (Visual Studio Code), a free code editor from Microsoft. It is fast and widely used by programmers and researchers worldwide. It also handles everything Python-related, from editing code to managing virtual environments and running .ipynb files (notebooks, introduced in Part 2).
We will cover how to install and get started with VSCode in Part 2. For now, think of it as the central app where you write and run your code.
What is a library?
Python by itself has limited capabilities. Features for reading data, running machine learning, and drawing charts are provided separately as libraries.
A library is a collection of useful features that someone else has built and shared. Python has hundreds of thousands of libraries contributed by researchers and engineers around the world. Once you install the ones you need, you can call them from your code. For example, instead of writing a regression model from scratch, you can install scikit-learn and train and run a machine learning model in just a few lines.
scikit-learn for machine learning (regression, classification, clustering, etc.)
pandas for tabular data (reading, aggregating, and reshaping Excel/CSV)
numpy for numerical computation and matrix operations
matplotlib / seaborn for charts and figures
openpyxl for reading and writing Excel files
scipy for scientific computing and statistics
In your code, one line like import sklearn makes all of that library's features available. Installing it takes a single command, pip install scikit-learn.
Each library has a version (e.g., scikit-learn 1.4.0), and behavior can differ between versions. This is why "environment setup," explained next, is important.
What is environment setup?
To run Python code, you need to prepare a "Python execution environment" on your PC. This process is called environment setup. It involves the four steps below.
- Create a project folder (e.g.,
my_first_analysison your Desktop) - Create a "virtual environment" inside that folder (with the command
python -m venv .venv). This creates a.venvfolder, a self-contained box for your project. - Install the libraries you need at the required versions (e.g.,
pip install scikit-learn pandas) inside the virtual environment. - Activate the virtual environment (with the command
.venv\Scripts\activateon Windows). When you run code with the environment active, that box's Python and libraries are used. In your code, you call a library with a line likeimport sklearn.
The reason for the virtual environment step is that different projects use different libraries and versions. Installing libraries directly on your PC, without a virtual environment, causes conflicts between projects. A virtual environment is a separate box for a single project, so it does not affect other projects.
Imagine setting up a dedicated "work room" for each project inside your PC. Each room has its own Python and its own set of libraries, completely independent of the others. Project A can use scikit-learn 1.4.0 while Project B uses scikit-learn 0.24, and the two coexist on the same machine without conflict. In technical terms, this idea is also called a "sandbox," meaning an isolated workspace.
The key point is that code runs correctly only when the right Python version and library versions are all aligned. Code written for scikit-learn 1.4 may not work on scikit-learn 0.24, and features available in Python 3.12 may not be available in Python 3.8.
Common problems such as "it worked on my machine but not on yours" and "the results differ even with the same code" almost always come down to version mismatches. That is why creating a virtual environment and managing versions is so important. A file called requirements.txt, covered later in the course, lets other people install exactly the same versions.
Why build a local environment?
There are two main ways to use Python. One is cloud-based (e.g., Google Colab, running in a browser), and the other is local (building an environment on your own PC). This course uses the local approach for the reasons below.
- Your data stays private. There is no need to upload unpublished research data to an external server.
- Full use of your PC's performance. Analysis speed depends on your machine. If your PC is powerful, you can use it to the fullest.
- Intuitive folder and file management. You work with files the same way you always do in Explorer (Windows) or Finder (Mac).
- Easy to package for reproducibility. As explained later, all you need to do is share the whole folder.
On the other hand, if your PC has limited performance or you need large-scale GPU computation, cloud-based options like Google Colab or university servers may be more suitable. The local skills you learn here also apply when using cloud environments.
The benefits of reproducibility in research
In recent years, more journals have begun asking authors to publish their raw data and analysis code when they submit a paper. Examples include PLOS ONE (Data Availability Statement required), Nature-family journals (Code & Data Availability requested), and eLife (open data policy). Agronomy journals such as Field Crops Research are also moving toward policies that strongly encourage sharing data and code.
Setting up a local Python environment makes it very easy to meet these requirements. You only need to organize your project folder as shown below and upload it to Zenodo or GitHub.
project/
├── .venv/ # Virtual environment (contains version info)
├── data/ # Raw data (Excel, CSV, etc.)
├── notebooks/ # Analysis scripts (.ipynb)
├── results/ # Output figures and tables
├── requirements.txt # List of libraries for rebuilding the environment
└── README.md # Usage instructions
With the whole folder, a third party can reproduce the exact same analysis by downloading it, creating a virtual environment, installing the libraries it needs, and running the script. This level of reproducibility is difficult to achieve with manual Excel workflows.
Overview of this course
From Part 2 onward, you will put all of the concepts explained here into practice. The course follows the flow below.
Setup
Vibe Coding
Reproducibility
Publishing
- Part 2: Environment Setup. Install VSCode, then create a folder and a virtual environment. You will go from Hello World all the way to outputting basic statistics.
- Part 3: Vibe Coding with LLM. Ask ChatGPT to write your code. You will also learn how to handle errors and how to improve the code over several exchanges.
- Part 4: Ensuring Reproducibility. Make your environment reproducible by others.
- Part 5: Publishing with Your Paper. Organize your folder, upload it to Zenodo and GitHub, and add a link in your paper's Appendix.
Parts 2 to 5 take about 3 to 5 hours in total. You can work through them in one day or take one part at a time. When you are ready, move on to Part 2.