Python Vibe Coding Course — Part 3
Ask ChatGPT to write your code
With the environment from Part 2 ready, this is where the course gets exciting. In this part, you will develop the habit of describing the analysis you want in plain English to an LLM, having it write Python code as an .ipynb file, and running it in your own VSCode. Even without knowing how to code, you can ask an LLM to write it for you. When errors occur, you can ask the LLM to fix them. This back-and-forth style is called "vibe coding."
Vibe Coding is a coding style where, instead of writing code yourself, you describe your intent in natural language and have an LLM write the code for you. Tell it "I want to run this analysis" or "I want to read this CSV and aggregate by column," and the LLM translates that into Python code.
For this course, the free versions of ChatGPT (OpenAI) or Claude (Anthropic) are more than sufficient. Both free plans can handle everything in this course.
Paid plans (ChatGPT Plus, Claude Pro) give access to more capable models with higher code accuracy. However, the free plan is plenty to start. Consider upgrading once you've gotten comfortable.
Before you start using an LLM, confirm one absolute rule upfront so you don't accidentally share sensitive information as you work through the examples.
Never send the following to an LLM:
· Raw experimental data (especially anything containing subject information or personally identifiable information)
· The text or figures of an unpublished manuscript
· Information covered by a confidentiality agreement in a collaborative project
· Personal information (names, addresses, IDs, etc.)
The only thing you should send to an LLM is the structure of your data (column names, what each column means, approximate row count). For example, the following kind of prompt is perfectly fine:
The key is to describe only the shape of your data to the LLM. The code runs entirely on your own PC, so the data itself never leaves your machine.
Both ChatGPT and Claude offer a Temporary Chat mode, where the conversation is not used for training data and does not appear in your chat history. This is useful for sensitive requests or when discussing your lab's internal data structure.
Using Temporary Chat does not mean it is safe to send actual data. Think of it as an additional safeguard on top of keeping shared information to the bare minimum.
As Step 02 established, you cannot send your raw data to the LLM. But without knowing your data structure (column names, types, row count), the LLM cannot write accurate code. The solution is a two-step workflow that forms the foundation of vibe coding: extract a structural summary of your data locally, then share only that structural information with the LLM. Skipping this step causes the LLM to assume incorrect column names or types — always start here.
Once you paste the output (e.g., "Columns are A, B, C; A is numeric, no missing values, min 0.5, max 12.3...") back into the LLM, it can return highly accurate code based on your actual data structure — without you having sent any of the actual data.
The most important skill in vibe coding is not learning Python syntax or memorizing useful libraries. It is understanding precisely what you want to do and communicating that to the LLM concretely and systematically.
LLMs are not magic — they infer code from the information you give them. A vague request like "please aggregate my data" gives the LLM no basis for deciding how to aggregate. Conversely, a specific request like "for each unique value in column A, calculate the mean and standard deviation of column B, sort by column A descending, and save the result as a CSV in the results/ folder" will almost always produce exactly what you want on the first try.
☐ Purpose: What is this analysis for?
☐ Input: What data, where, and in what structure? (paste the structural info from Step 03)
☐ Processing: What specific calculation or aggregation do you want?
☐ Output: What to save, where, and in what format?
☐ Constraints: Which libraries to use, what behavior to avoid, etc.
Simply keeping this checklist in mind will dramatically improve the quality of code the LLM returns. Conversely, if you yourself are unclear about what you want, no amount of prompting will produce the right result. Half of the analysis is decided in the "articulate your intent" stage — before any code is written.
Open ChatGPT (or Claude) and start a new chat. Both ChatGPT and Claude can now output an .ipynb file directly and make it available for download. There is no need to copy and paste code cell by cell. In your first request, explicitly ask: "Please write this as an .ipynb file and make it available for download."
Turning on web search improves accuracy: For questions about the latest library specifications or up-to-date error fixes, enable the web search icon (globe icon) in the ChatGPT input bar before sending your prompt. Claude has a similar web search feature. This is especially useful for newer libraries or version-specific questions.
Once the LLM generates the file, a download link will appear. Follow these steps:
analysis.ipynb from the link (it typically saves to your Downloads folder)analysis.ipynb into the project folder you created in Part 2 (e.g., my_first_analysis/)analysis.ipynb to open and run itIf you forget to move the file into the project folder, the code's relative paths (e.g., "sample_data.xlsx") will fail to find the data, producing a FileNotFoundError. Always place the notebook in the same folder as your data.
Open the downloaded analysis.ipynb in VSCode. Run the cells from top to bottom (Shift + Enter). As you review the output, ask the LLM in plain English for any changes you want.
If you want to fundamentally change the approach, simply ask for a full rewrite.
Errors will happen. In fact, it would be unusual for the first run to be error-free. There is no need to panic when errors appear. Simply copy the entire error message and paste it into ChatGPT — that is all you need to do.
The LLM will infer the cause from the error message and return a fixed file. Download the corrected version and run it again — repeat this cycle as needed.
ModuleNotFoundError: A required library is missing → run pip install library-name in the terminal
FileNotFoundError: The file path is wrong → check the filename and location
KeyError: A column name is wrong → make sure it exactly matches the column names in your Excel file
SyntaxError: A coding mistake → ask the LLM to fix it
As you work through analyses, you may encounter situations where "this library only supports up to Python 3.10" or "that library requires Python 3.12 or later." The LLM may also suggest "please use Python 3.X" while helping you resolve an error.
To change your Python version, follow these steps:
.venv folder inside your project folder using Explorer/Finder (delete the whole folder).py -3.10 -m venv .venv; on Mac/Linux: python3.10 -m venv .venv..venv\Scripts\Activate.ps1 to activate → then pip install ... to reinstall..venv via "Select Kernel" in VSCode.Think of virtual environments as disposable work rooms. Don't hesitate to delete and recreate one. There are no important settings stored inside. As long as you keep your requirements.txt (explained in Part 4), recreation is straightforward.
The repeating pattern in real-world analysis looks like this:
As you go through this cycle repeatedly, you develop an intuition for "this kind of prompt produces this kind of code." You don't need to memorize Python syntax. Instead, you train the skill of articulating what you want clearly.
In Part 4, you will learn how to create a requirements.txt file that lets others reproduce the analysis environment you built here.