FROM DATA TO THESIS: Using Python for Non-Technical
Playground, Chapter 18: Using AI with Python

How to use this project
1. Open this folder in VS Code, PyCharm, or your chosen Python editor.
2. Open exercises.py. It has four parts:
   A. Practise the chapter       the book's exercises, with blanks (______) to fill
   B. Go further                 new exercises beyond the book
   C. Check your understanding   short questions to answer in your own words
   D. Do it yourself             open tasks: no starter code and no answers
   Run lines or sections interactively (Shift+Enter or via terminal: python exercises.py).
3. Check parts A to C in solutions.py, after you have tried each one yourself.

The exercises need these packages (install once):
pip install pandas numpy scikit-learn

Everything except live model execution runs directly without external AI APIs.
The chapter uses a free local model, which needs no API key and keeps all data on
your computer:
- Install Ollama from ollama.com, then run this once in a terminal:
    ollama pull gemma4:e4b
  (or use any local model supported by Ollama).
- In Python, you can interact with Ollama using the official `ollama` package
  or standard HTTP requests to `http://localhost:11434/api/generate`.
Alternatively, if using an online model (e.g. OpenAI, Anthropic), set your API key
in your environment variables (e.g. `export OPENAI_API_KEY="your-key"` or via `.env`).
Never put a key in a script. Real research data may only be sent to an online service
if your ethics approval specifically permits third-party cloud data transmission.

Files
- exercises.py               the four parts, with starter code for parts A and B
- solutions.py               solutions for parts A and B, model answers for part C
- students.csv              one row per student in the wellbeing study (600 students)
- semesters.csv             one row per student per semester
- open_responses.csv        the students' answers to the open question
- open_responses_coded.csv  200 answers hand-coded into seven themes
- ai_coding_results.csv     the chapter's saved language-model coding (gemma4:e4b)

Please note: Elaf and her data are fictional. The data was generated by a
computer program to look realistic, and its patterns were built in by the
author. It describes no real people and is not evidence about real students;
do not cite or use it as research findings.
Browser exercises for this chapter are at:
https://polla-fattah.github.io/data2thesis_python/playground/chapter18.html
