File size: 792 Bytes
3040a19
 
f0248c9
 
3040a19
 
 
 
f0248c9
3040a19
 
 
 
 
 
 
 
 
 
 
 
f0248c9
3040a19
f0248c9
 
3040a19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import csv, json

def extract_list():
    csvfile = "mediators.csv"

    header_to_extract = "mediator areas of practice"

    values = []
    with open(csvfile, 'r', encoding='utf-8') as file:
        csv_reader = csv.DictReader(file)
        for row in csv_reader:
            if header_to_extract in row:
                text = row[header_to_extract]
                practice_list = text.split('|')

                for practice in practice_list:
                    new_practice = practice.strip()

                    if not new_practice in values and not new_practice.isdigit():
                        values.append(new_practice)

    jsonfile_path = "list.json"

    with open(jsonfile_path, 'w', encoding='utf-8') as file:
        json.dump(values, file, indent=4)
    return values