Menu

1 / 3

Catch a pandas join that silently multiplies attendance rows

DEV Community: python·Wenlo·about 14 hours ago
#4jsTzPnN
#devtopython#devto#dev#roster#report
Reading 0:00
15s threshold

Wenlo

Posted on Nov 15

AI-assisted

An attendance table has five check-ins. After a join, it has six rows. Nothing crashed, but the report is already wrong. A duplicated learner ID in the roster produced two matches for one check-in. This fictional example makes that failure visible before building any totals.

Run the example

All illustrative records are fictional. Save the following as attendance_join.py. The complete script was run in PythonIDE on iPhone; the screenshots show the actual source and output.

import pandas as pd

# Fictional learner roster and workshop check-ins. roster = pd . DataFrame ( { 'id' : [ 'S1' , 'S2' , 'S2' , 'S3' , 'S4' ] , 'name' : [ 'Ari' , 'Bo' , 'Bea' , 'Cy' , 'Dee' ] , } ) visits = pd . DataFrame ( { 'id' : [ 'S1' , 'S2' , 'S1' , 'S9' , 'S3' ] , 'session' : [ 'AM' , 'AM' , 'PM' , 'PM' , 'PM' ] , } ) print ( 'FICTIONAL ATTENDANCE CHECK' ) print ( 'Visit rows before join:' , len ( visits ) ) unsafe = visits .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.