Created
November 22, 2021 23:19
-
-
Save cbare/98be2966561daefdc006f8325bda5130 to your computer and use it in GitHub Desktop.
Convert JSON output from V7 Darwin to csv.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Convert JSON output from V7 Darwin to csv. | |
""" | |
import json | |
import os.path | |
import pandas as pd | |
filenames = [f"{name}.json" for name in list('abcde')] | |
data_dir = "data/lizzie-reader-study-test-part-1" | |
rows = [] | |
for filename in filenames: | |
path = os.path.join(data_dir, filename) | |
with open(path) as f: | |
data = json.load(f) | |
for annotation in data["annotations"]: | |
for attribute in annotation["attributes"]: | |
rows.append(( | |
data["dataset"], | |
data["image"]["filename"], | |
annotation["annotators"][0]["full_name"], | |
annotation["name"], | |
attribute | |
)) | |
df = pd.DataFrame(data=rows, columns=["dataset", "filename", "annotator", "annotation_name", "attribute"]) | |
df.to_csv("lizzie-reader-study-test-part-1.csv", index=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment