#π Recommend me a library, or some tip to get this table correctly
16 messages Β· Page 1 of 1 (latest)
@young lynx
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
I dont understand the question
I need to extract that table as a .csv, using python, but most of the online tools I've tried mess the second to lasst line since it priorizes layout over different text color, so it looks like:
Usos: Abastecimiento,Riego | Hidroelectrico
That's because they look at it this way:
Now, I would like to know what's a good python library for this, because I'm pretty sure most will look at the table the same way, first they try to think of a layout and wathever falls on one side is considered part of one column, now I have more pdf documents like this, so manually correcting this would be a long task, so I wonder if some library will have mor granular control or will be clever enough to notice each text has different color and therefore is a different column
tbh, idk what a ,csv file is probably not the right guy to be answering this, gl tho
lowkey tho throw it into chat
I've dealt with something like this before. As long as you can get the text left -> right then top -> bottom, and as long as everything is single line, and as long as : is always used only as the separator, simply splitting lines on : will work. I had to do a lot more work since my data had multi-line entries. I used PyMuPDF since as long as the PDF has the text as some sort of actual text, it is the most consistent library I have found for the left -> right then top -> bottom text extraction.
PyMuPDF is a high-performance Python library for data extraction, analysis, conversion & manipulation of PDF (and other) documents.
More specifically, try extractText. If that gives a consistent processable output, all good. If that doesn't work, then extractBlocks. If the blocks still don't give a useful output, then extractWords.
PyMuPDF is a high-performance Python library for data extraction, analysis, conversion & manipulation of PDF (and other) documents.
Thanks a lot, there's almost always a : unless it's some new section, it's always a two colum table as well, I have no problem with the code (nowdays with chatGPT this low level questions are solved) can I ping you when/if it works?
For pdfs with text I've used pypdf and pdfminer, both are very nice, I had also heard about pyMuPDF before, hope that one works
Since it is two columns, then extractText most likely won't work for you, since it does a naive left -> right top -> bottom reading. Still worth trying since if it works it will save you a ton of time, but probably won't. extractBLOCKS would then work since it gives you the exact x and y position of every block, so you can manually split them into the left and right half.
Since I have already struggled with this a lot, feel free to ping me whever you need help/open another one of these issues. I'd be my pleasure to help someone else out of the PDF hellscape.
There is also always the nuclear option of extractDict, which gives you basically all the information possible, including stuff like font and color, which would almost certainly work based on how those images look, but would also be the hardest to work with.
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.