Singlefile_CRF_1.py

mail@pastecode.io avatar
unknown
python
a year ago
2.1 kB
1
Indexable
Never
import pandas as pd
import json
import os

# Initialize the dictionary template
json_template = {
    "performing_site": "",
    "subject_id": "",
    "experimenter_name": "",
    "experiment_date": "",
    "experiment_time": "",
    "eyetracker_calibration_quality": "",
    "errors_problems_setup": "",
    "practice_quantity": "",
    "notes_run_1": "",
    "notes_run_2": "",
    "notes_run_3": "",
    "notes_run_4": "",
    "notes_run_5": "",
    "notes_run_6": "",
    "notes_run_7": "",
    "notes_run_8": "",
    "notes_t1": "",
    "errors_problems_after_scanning": ""
}

item_to_json_key = {
    "Performing site": "performing_site",
    "Subject ID": "subject_id",
    "Experimenter Name": "experimenter_name",
    "Experiment Date": "experiment_date",
    "Experiment_time": "experiment_time",
    "Eyetracker calibration quality": "eyetracker_calibration_quality",#
    "Errors/Problems: Setup": "errors_problems_setup",
    "Practice quantity": "practice_quantity",
    "Notes: Run1": "notes_run_1",
    "Notes: Run2": "notes_run_2",
    "Notes: Run3": "notes_run_3",
    "Notes: Run4": "notes_run_4",
    "Notes: Run5": "notes_run_5",
    "Notes: Run6": "notes_run_6",
    "Notes: Run7": "notes_run_7",
    "Notes: Run8": "notes_run_8",
    "Notes: T1": "notes_t1",
    "Errors/Problems after scanning": "errors_problems_after_scanning"
}

# Excel File Path
excel_path = "C:/Users/kyle.kahraman/Seafile/shared_Kyle_Prav/FMRI_subjects/SC101/SC101_CRF_V1.xlsx"
df = pd.read_excel(excel_path, names=['Item', 'Value'])

# Iterate through the DataFrame to populate the JSON template
for index, row in df.iterrows():
    item = row['Item']
    value = row['Value']
    json_key = item_to_json_key.get(item, None)
    if json_key:
        json_template[json_key] = value

# Save the populated JSON to a file
output_json_file = "c:/users/kyle.kahraman/Seafile/shared_Kyle_Prav/scripts/kyle work in progress/FMRI Population/CRF_1_FMRI.json"
with open(output_json_file, 'w') as json_file:
    json.dump(json_template, json_file, indent=4)

print("JSON file has been created.")