vinhngba2704's picture
First commit to this repo
51db8d1
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}")