Professional Documents
Culture Documents
Code Example
Code Example
import os
import pandas as pd
import glob
# Read data from the Excel file and extract the first 8 characters from 'PATIENT ID'
data = pd.read_excel('/home/emth/Desktop/costa/CORYS_orig.xlsx', usecols='B, G')
ids_from_excel = data['PATIENT ID '].str.replace(' ', '').str[:8]
# Find matches between image files and Excel data based on the first 8 characters of IDs
matched_file = []
for image_directory in image_directories:
image_files = glob.glob(os.path.join(image_directory, '*.dcm'))
image_ids_trimmed = [os.path.splitext(os.path.basename(image_file))[0][:8] for image_file
in image_files]