Spaces:
Build error
Build error
File size: 915 Bytes
51db8d1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import os
import json
import pandas as pd
# Write the json result
def saving_json(data, json_path: str):
try:
# Ensure the directory exists
os.makedirs(os.path.dirname(json_path), exist_ok=True)
# Write the data to the JSON file
with open(json_path, "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=4)
print(f"Data successfully saved to: {json_path}")
except Exception as e:
print(f"Failed to save JSON file. Error: {e}")
def saving_excel(data: pd.DataFrame, excel_path: str):
try:
# Ensure the directory exists
os.makedirs(os.path.dirname(excel_path), exist_ok=True)
# Save DataFrame to Excel file
data.to_excel(excel_path, index=False)
print(f"Data successfully saved to: {excel_path}")
except Exception as e:
print(f"Failed to save Excel file. Error: {e}") |