Reading Code
LLMs are great at generating code, but as a data analyst, you need to be able to understand and verify what the code is doing.
Why Reading Code is Essential
Even if an LLM writes the code for you, you must be able to:
- Check if the logic makes sense – Does it do what you actually asked for?
- Understand the code structure – What happens at each step?
- Spot errors or inefficiencies – Is there a better or cleaner way?
Being able to read code—especially code you didn’t write—is a critical skill. It takes time to develop, but it is essential when using AI.
Read the AI’s Explanation Carefully
Always read the AI’s accompanying message which goes with the code. It often contains critical information like:
- Import statements or dependencies you need to install
- Assumptions the AI made about your data or environment
- Explanations of why it chose a particular approach
- Limitations or caveats about when the code will or won’t work
- Alternative approaches it considered
By reading these messages, you can spot incorrect assumptions early, understand the reasoning behind the implementation, and catch potential issues before running the code. This is part of treating AI as a collaborator—not just a code generator.
Verify packages AI suggest to install. Attackers use “typosquatting”—creating malicious packages with names similar to popular libraries. This is brought up later on in Practicing Responsible AI.
Reading Pandas Code
When working with Pandas, reading code is about understanding how the data transforms at each step. Since Pandas code often chains multiple operations, it can be tricky to follow. To get better at reading Pandas code, think in terms of data flow:
- How does the DataFrame change at each step?
- What columns are added, removed, or modified?
- Are rows being filtered, sorted, or grouped?
- What columns are added, removed, or modified?
- What do the methods actually do?
- Don’t assume—read the Pandas documentation for methods you don’t fully understand.
- Many methods take parameters that change their behavior, so small tweaks can make a big difference.
- Don’t assume—read the Pandas documentation for methods you don’t fully understand.
- Use tools to visualize and verify
- Print
df.head()at key points to see how the data looks.
- Try
df.info()anddf.describe()to get a snapshot of structure and statistics.
- Use these functions to output text formats which can be directly shown to LLMs.
- If you’re unsure, ask an LLM to explain the code—it can break down each step for you.
- Print
Thinking Like Pandas
Pandas is designed to operate on entire datasets, so avoid thinking in terms of loops over rows. Instead, focus on:
- Vectorized operations – Pandas is optimized for applying functions across whole columns.
- Method chaining – Many Pandas operations can be stacked together for efficient workflows.
- Memory efficiency – Some operations create copies of data, while others modify in place (
inplace=True).
📌 Pandas documentation: https://pandas.pydata.org/
Explain in Plain English Exercises
A powerful way to build your code reading skills is to try Explain in Plain English exercises.
You’ll be shown a code snippet. Your task is to:
- Read it carefully.
- Write a brief high-level explanation of what the code is doing.
- Submit your explanation for feedback from an LLM.
Let’s practice with two examples.
📊 Exercise 1: Filtering and Sorting
Explain the above code snippet?
📈 Exercise 2: Grouping and Aggregation
Explain the above code snippet?
Practice Helps You Grow
Explaining code helps you:
- Understand data flow, transformations, and aggregations
- Identify errors or inefficiencies
- Strengthen your ability to think in Pandas
Use these strategies any time you read code—even when using AI.
The more you practice, the more confident you’ll become at spotting what works… and what doesn’t! 💪
Making your own Explain in Plain English Exercises
To practice and keep learning how to read Data Analysis code, you can make your own tutoring chatbot.
Here is a prompt that you can use to make unlimited Explain in Plain English coding exercises:
You are a helpful and friendly coding buddy.
You help me learn to use AI-Assisted coding effectively.
- You can give details on how AI can assist with coding.
eg explain code, help debug code, comment code, optimize code
- You help me learn and understand Pandas and data processing fundamentals.
- The main way you can do this is with explain in plain english exercises.
This means you give me a code snippet and ask them what it does.
Do not give descriptive function names or include comments.
- You then provide feedback on my code description.
- You begin by asking me whether I am a beginner,
have some experience or an advanced user.
This helps you know the correct level to target your exercises.
YOU MUST DO THIS.
- In Explain as Plain English exercises do not include
comments or hints or use descriptive function names.
These are exercises to help the learner learn to read and understand code.
Make learning fun - Use emoticons.