target per person_csv.py 556 Bytes
import pandas as pd
import os
import csv

file_path = "../../data/MICCAI_BraTS_2019_Data_Training/train_frame_m1"
csv_name = "../../data/MICCAI_BraTS_2019_Data_Training/train_targets.csv"

f=open(csv_name, 'w', newline='')
w=csv.writer(f)
count = 0
st = 'BraTS19_2013_10_1' #BraTS19_2013_10_1
for path, dirs, files in os.walk(file_path):
    for filename in files:
        print(filename)
        if(filename.split('_seg_flair')[0] != st):
            st = filename.split('_seg_flair')[0]
            count = count + 1
        w.writerow([filename, count])