我有一个包含许多表格的PDF。 )我将此PDF在线转换为CSV,以便更轻松地提取所需的数据。)
CSV行由许多列组成,但是每个表仅包含3列,因此很难知道哪个列引用了单元格。
我还应该提到一个单元格可以由多个行和一列组成。 An example of a table。
那么有什么方法可以提取这些细胞吗?
import csv
import re
class PDF_EXTRACTOR:
FILE_NAME=None
Ttableau=None
NUMBER_OF_PAGES=None
def __init__(self,fn):
self.FILE_NAME=fn
self.Ttableau=0
self.NUMBER_OF_PAGES=0
def EXTRACT_CELLULE(self):
csv.register_dialect('mydialect',delimiter =',',skipinitialspace=True)
print(csv.list_dialects())
with open(self.FILE_NAME,'r',encoding='utf8',errors='ignore') as csvFile:
reader = csv.reader(csvFile, dialect='mydialect')
for index, row in enumerate(reader):
print(row)
我期望这样的输出:
["Region 1","Region 2", "Region3]
["8,3-9","AUXILIAIRES DE LA MÉTÉOROLOGIE 5.54A 5.54B 5.54C",""]
["70-72","70-90","70-72"]
["RADIONAVIGATION 5.60","FIXE","MARITIME 5.60"]
但是我得到了:
['7 450-8 100', 'FIXE', '', '', '', '']
['', 'MOBILE sauf mobile aéronautique (R)', '', '', '', '']
['', '5.144', '', '', '', '']
['8 100-8 195', 'FIXE', '', '', '', '']
['', 'MOBILE MARITIME', '', '', '', '']
['8 195-8 815', 'MOBILE MARITIME', '5.109', '5.11', '5.132', '5.145']
['', '5.111', '', '', '', '']
['8 815-8 965', 'MOBILE AÉRONAUTIQUE (R)', '', '', '', '']
['8 965-9 040', 'MOBILE AÉRONAUTIQUE (OR)', '', '', '', '']
['9 040-9 305', '9 040-9 400', '', '', '', '9 040-9 305']
['FIXE', 'FIXE', '', '', '', 'FIXE']
['9 305-9 355', '', '', '', '', '9 305-9 355']
['FIXE', '', '', '', '', 'FIXE']
['Radiolocalisation 5.145A', '', '', '', '', 'Radiolocalisation 5.145A']
['5.145B', '', '', '', '', '']
['9 355-9 400', '', '', '', '', '9 355-9 400']