Spaces:
Runtime error
Runtime error
Download data/convert-tsv-JSON.py from commonman/Unit-Creator-v1: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/spaces/commonman/Unit-Creator-v1/resolve/main/data/convert-tsv-JSON.py
- Command line
-
hf download hf://spaces/commonman/Unit-Creator-v1/data/convert-tsv-JSON.py
-
curl -L -o convert-tsv-JSON.py https://huggingface.co/spaces/commonman/Unit-Creator-v1/resolve/main/data/convert-tsv-JSON.py
1.36 kB
| import pandas as pd | |
| import json | |
| # Load data from TSV file | |
| df = pd.read_csv('MYP_Key_Related_Concepts.tsv', sep='\t') | |
| # Print the column names | |
| print(df.columns) | |
| # Print the first few rows of the DataFrame | |
| print(df.head()) | |
| # # Load data from TSV file | |
| # df = pd.read_csv('MYP_Key_Related_Concepts.tsv', sep='\t') | |
| # Initialize list to hold subject data | |
| subjects = [] | |
| # Iterate over rows in DataFrame | |
| for index, row in df.iterrows(): | |
| subject = {} | |
| subject['Subject Name'] = row['Subject'] | |
| # Get key and related concepts from row | |
| subject['Key Concepts'] = [v for k, v in row.items() if 'Key' in k and pd.notna(v)] | |
| subject['Related Concepts'] = [v for k, v in row.items() if 'Related' in k and pd.notna(v)] | |
| # Placeholder for aims and criteria | |
| subject['Aims'] = 'Aim text goes here...' | |
| subject['Criteria'] = [ | |
| { | |
| 'Criterion': f'Criterion {i+1}', | |
| 'Strands': [f'Strand {j+1}' for j in range(5)] # change range depending on number of strands | |
| } for i in range(4) # change range depending on number of criteria | |
| ] | |
| # Append subject to subjects list | |
| subjects.append(subject) | |
| # Combine all subjects into final dictionary | |
| data = {'MYP Subjects': subjects} | |
| # Write data to JSON file | |
| with open('MYP_Subjects.json', 'w') as outfile: | |
| json.dump(data, outfile, indent=4) | |