Menu

The table you extracted from a PDF has silently wrong numbers. Here are 4 checks that catch it in Python
📰

The table you extracted from a PDF has silently wrong numbers. Here are 4 checks that catch it in Python

DEV Community: beginners·rene·12 days ago
#Qp00B9ZM
#devtobeginners#devto#dev#rows#total
Reading 0:00
15s threshold

You pull a table out of a PDF, load it into your script, and the total is off by 1,200. No error, no warning. The extractor did exactly what it was told. The numbers are just wrong.

Here is a six-row example of what extraction can hand you:

rows = [ [ " Item " , " Qty " , " Amount " ], [ " Hosting " , " 1 " , " 1,200.00 " ], [ " Support " , " 2 " , " (300.00) " ], # negative in parentheses [ " Domain " , " 1 " , " 15.00 " ], [ " Item " , " Qty " , " Amount " ], # header repeated: a page break leaked in [ " Backup " , " 1 " , " 80.00 " , " x " ], # ragged row: shifted column [ " Total " , "" , " 995.00 " ], ]

Enter fullscreen mode

Exit fullscreen mode

Libraries such as pdfplumber give you rows like these. They do not tell you whether the rows are trustworthy.…

Continue reading — create a free account

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