# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import json
import os

# Opening JSON file 
with open(os.path.expanduser('~/Desktop/Datasets/Trento_events.json')) as f:
    file = json.load(f)

# +
#make a set of all the unique categories 
unique_cat = set(item['Tipo_evento'] for item in file)

unique_cat = list(unique_cat)

print(len(unique_cat))

# +
#enumerate the categories and create a new JSON file
event_categories = []
x = 1
for cat in unique_cat:
    cat_name = cat
    cat_id = x
    x = x + 1
    
    catageory = {'ID': cat_id, 'Category': cat_name}
    event_categories.append(catageory)
#     print(tour_categories)
    
with open('Event_categories.json','w') as f:
    json.dump(event_categories,f,indent=4)   
# -

print(event_categories)

# +
# impute the new category IDs in the Tour_data file
new_file = []
for item in file:
    for category in event_categories:
        if item['Tipo_evento'] == category['Category']:
            item['Tipo_evento'] =  category['ID']
#             print(item)
    new_file.append(item)            
           
with open('Trento_events_enumerated.json','w') as f:
    json.dump(new_file,f,indent=4) 
# -



StarcoderdataJupyterScriptsDedupFiltered