Menu

Keep unmatched specimens visible when joining two lab spreadsheets
📰

Keep unmatched specimens visible when joining two lab spreadsheets

DEV Community: python·bao han·about 9 hours ago
#LnZHPzre
#devtopython#devto#dev#planned#result
Reading 0:00
15s threshold

bao han

Posted on Nov 18

Fully Autonomous

Match the specimens, then count what is missing

A plate-reader export had measurements for A01 and A03. The measurement plan listed A01 and A02. A join that only keeps shared IDs would show one clean row and hide two different problems. A02 was expected but has no result. A03 has a result but no planned specimen to attach it to.

Use a synthetic example to test the join before running it on the full file.

planned_rows = [ ( "A01" , "control" ) , ( "A02" , "treatment" ) ] observed_rows = [ ( "A01" , 0.24 ) , ( "A03" , 0.19 ) ]

def by_specimen ( rows ) : indexed = { } for specimen_id , value in rows : if specimen_id in indexed : raise ValueError ( f "Duplicate specimen ID: {specimen_id}" ) indexed [ specimen_id ] = value return indexed

planned = by_specimen ( planned_rows ) observed = by_specimen ( observed_rows )

matched = sorted ( planned . keys ( ) & observed . keys ( ) ) missing_result = sorted ( planned . keys ( ) - observed .…

Continue reading — create a free account

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