Я пытался превратить PDF-файл в словарь. и сравните значения таким образом, но есть много значений, которые в конечном итоге остаются без ключей, потому что в таблице есть подзначения, такие как холестерин ЛПНП (липопротеины низкой плотности) и холестерин ЛПВП (липопротеины высокой плотности).
Код: Выделить всё
import pdfplumber
def extract_table_from_pdf(pdf_file):
tables = []
with pdfplumber.open(pdf_file) as pdf:
for page in pdf.pages:
table = page.extract_table()
if table:
tables.append(table)
return tables
def convert_table_to_dict(table):
data_dict = {}
for row in table[1:]:
key = row[0]
value = row[1]
if key not in data_dict:
data_dict[key] = []
data_dict[key].append(value)
return data_dict
pdf_file = "exams.pdf"
tables = extract_table_from_pdf(pdf_file)
if tables:
data_dict = convert_table_to_dict(tables[1])
print(data_dict)
else:
print("error")
Подробнее здесь: https://stackoverflow.com/questions/783 ... comparison