How to clean and analyse a survey CSV with pandas
Give an agent a messy survey export. It cleans it, runs the tests and draws the charts, and it tells you what it removed. Then you check its numbers. This post follows a real run.
Almost every final-year project has a spreadsheet of survey answers, and almost every export is messy. People type "M", "male" and "man". They write "12hrs" in a number box. Some answer twice. Cleaning that by hand takes an evening, and a mistake there can change the result.
An agent on awx has a real computer with Python on it, so it can do the whole job and keep the scripts. We gave it a made-up study-habits survey and asked for the numbers a dissertation chapter might need. The most useful part was the list of things it told us to check.
How we ran it
We have no real dissertation data to share, so the agent first made a stand-in file, survey.csv, with 118 invented respondents and the usual mess: ages of 150 and 2024, study hours of -3 and 168, a 26-hour night of sleep, gender written as M, man, nonbinary and PNTS, yes and no written as Y, true and 1, comma decimals like 3,45, units inside cells like 12hrs, missing answers written ten different ways, five exact duplicates and four sneaky near-duplicates.
Every number below comes from that invented file. They show how the workflow behaves and mean nothing about students. We used a Small computer.
The first message
I am a final-year student with a messy survey CSV for my
dissertation, and I want to analyse it with Python and pandas.
I do not have the real file here, so first make a stand-in in
/home/agent/survey: survey.csv with about 120 made-up responses
(columns: id, age, gender, hours_study_per_week, hours_sleep,
used_ai_tools, gpa, satisfaction 1-5). Make it messy the way real
survey exports are. Then clean it and tell me exactly what you
removed or changed and why. Report the mean and median of hours
studied and GPA, the correlation between study hours and GPA, and
whether students who use AI tools have a different GPA, with a
proper test, and say how much to trust it with this sample size.
Save two charts as PNG files in /home/agent/survey/charts. At the
end, list anything in your own analysis that I should double-check
before putting it in my dissertation.
Two sentences matter most: "tell me exactly what you removed or changed and why", and the last one, which makes the agent argue against its own work. With the real file you would say "I uploaded survey.csv to the Files tab" and leave out the stand-in part.
The agent worked for nine minutes and 55 steps. It installed pandas, NumPy, SciPy and matplotlib into a private folder of its own, so nothing on the computer was changed. It asked us before it wrote files and before one command that deleted its own output, and we read each one before pressing Approve. Its first three tries to save the long cleaning script failed because it gave the file tool a path in the wrong form. It noticed and split the script into two files.
What it cleaned, and why
- 10 of 127 rows removed. Five were identical copies and three were the same person typed again with a different id format. The last two were one person, id 34, who answered twice with two different GPAs. It dropped both and did not guess which was true.
- 22 impossible cells blanked, with the row kept. These were the ages, hours, a 26-hour day, GPAs of 4.6 and 5.0 on a 4.0 scale, and satisfaction scores of 0, 6 and "very good". The rest of that person's answers stayed.
- 140 labels standardised. M became Male, and y, true and 1 became yes. The answers "sometimes" and "maybe" became missing, because forcing them into yes or no would have been inventing data.
- Numbers stored as text were converted, so 3,45 became 3.45 and 12hrs became 12.
- Nothing was filled in. Guessing a missing GPA or study time would manufacture the very relationship you are testing.
Every change went into cleaning_log.csv, one line each with the id, the old value, the new value and the reason. The original survey.csv was left alone. Your supervisor, or an examiner, can ask what you did to the data, and this file is the answer.
What it found
- Study hours and GPA: a correlation of 0.45, which is about 20% of the differences in GPA, or +0.022 GPA for each extra weekly hour.
- AI tools and GPA: users averaged 3.62 and non-users 3.56. The 95% interval for the difference runs from -0.11 to +0.23 and the Welch t-test gives p = 0.50.
The wording of the second result is what we wanted from it. The agent wrote "no evidence of a difference, but that is not evidence of no difference". With 56 and 37 students the test had about 10% power, and it could only reliably catch a gap of around 0.24 GPA points. A weaker tool would have said "AI use does not affect grades". It also repeated the comparison with study hours and sleep taken into account, and the answer stayed non-significant (p = 0.099).
The agent checked these two charts in the computer's own browser before it called them done. It found a title running off the edge and a legend sitting on top of some points, and fixed both.
We checked its numbers
The agent can be wrong and sound sure, so we did not take its table on trust. We opened a terminal on the computer and recomputed the headline figures from cleaned_survey.csv with a short command of our own:
The counts, means, medians, correlation and t-test all matched. We did not recheck the power figure or the adjusted comparison, so treat those two as the agent's word until you have.
The agent also checked itself. After writing REPORT.md, it compared the report with the program's actual output and corrected two mistakes: it had written 26 blanked cells when the log says 22, and it had said a test would need more than 1,000 students per group when its own calculation gave about 800. At the end it deleted every result and ran the whole pipeline again from the raw file. That found a real bug, since the analysis script assumed the charts folder already existed. It fixed it, so the next person can run the folder from scratch.
What to double-check
This is the agent's list, with our notes. It is a good checklist for any analysis an agent does for you:
- Is the data real? Ours was invented. Run the same scripts on your own file.
- The GPA scale. It assumed 0 to 4.0 and blanked anything above. If your university uses 0 to 5, 0 to 10 or percentages, it would delete valid top marks. The limit is one line in
clean_survey.py. - The judgement calls. A ceiling of 60 study hours and an age window of 17 to 60 are guesses. A mature student or a medical student in exam week would be removed by mistake.
- Duplicate detection is a heuristic. Read the removed rows in the log.
- "Sometimes" and "maybe" became missing, which can change the AI comparison. Consider three groups instead of two.
- What "used AI tools" meant on your questionnaire. The whole comparison rests on that question.
- The choice of test. It used Welch's t-test. Your supervisor may expect another one, and your methods chapter should say which you used.
- The ceiling at 4.00. Many students sit at the top mark, which weakens a correlation. The scatter chart shows the row of dots. Name it in your limitations.
Using your real file
- Open the computer, go to the Files tab and press Upload. Then tell the agent where the file is. Ask it to keep the original untouched and write the cleaned data to a new file, as it did here.
- Say what each column means and what the valid ranges are, for example "GPA is out of 5.0". That removes the biggest guess.
- Ask for the same two extras: the change log, and the list of things to double-check.
- Read the scripts it saved. They are plain Python, and the point is that you can explain every step in a viva.
Before you upload anything, check your ethics approval and consent form. Survey data about people may not be allowed to leave your university systems, and a cloud computer is outside them. Remove names, emails and student numbers first.
What it cost
The computer was on for about 14 minutes, most of it the agent working and the rest us checking. A Small computer is RM0.03 an hour, and the balance moved from RM0.98 to RM0.97. The Usage page shows each run, with its steps and the time it took. How running time and credit work has the details, and Small or Large helps you choose a size if your file is big.
Cautions
- Your examiner marks your work. You must understand every cleaning step and every test you report. Check your university's rules on AI help with a dissertation, and say in your methods what the agent did.
- An agent can be confidently wrong. Recompute your key results another way, as we did.
- Do not clean data to get the answer you hoped for. Write the rules down before you look at the results, and keep the log.
- Keep your own copy of the raw file, the scripts and the log.
awxis in early alpha.
Keep reading
- How to work on LaTeX with AwanBox
- How to practise SQL with PostgreSQL: SELECT, JOIN, GROUP BY
- How to learn Python and Linux with a tutor beside you
- How to back up and restore a cloud computer: a tested guide
Getting started
Sign in with your Google account and open a chat on a Small computer. Paste the first message from this post, run it on the stand-in file first, then upload your own data once you trust the routine.
Awi, signing off.