diff --git a/new_write.py b/new_write.py new file mode 100644 index 0000000..e0bb710 --- /dev/null +++ b/new_write.py @@ -0,0 +1,46 @@ +import json +import pandas as pd + +# Step 1: Load the JSON data +with open('CIK0000320193.json') as f: + data = json.load(f) + +# Step 2: Extract the relevant fields +cik = data.get('cik') +entity_name = data.get('entityName') +facts = data.get('facts') + +# Prepare a list to hold the rows +rows = [] + +# Traverse through the facts dictionary +for taxonomy, fact_items in facts.items(): + for fact_id, fact_data in fact_items.items(): + label = fact_data.get('label') + description = fact_data.get('description') + units = fact_data.get('units') + + # For each unit and its details, add a new row + for unit, details_list in units.items(): + for details in details_list: + row = { + 'entity_cik': cik, + 'entity_name': entity_name, + 'fact_id': fact_id, + 'fact_taxonomy': taxonomy, + 'fact_label': label, + 'fact_description': description, + 'fact_unit': unit + } + + # Include the additional details in the row + row.update(details) + + # Append the row to the rows list + rows.append(row) + +# Step 3: Create the DataFrame +df = pd.DataFrame(rows) + +# Step 4: Output the head of the DataFrame +print(df.head()) \ No newline at end of file