-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathearnings_quality_results_exporter.py
More file actions
66 lines (57 loc) · 2.91 KB
/
earnings_quality_results_exporter.py
File metadata and controls
66 lines (57 loc) · 2.91 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from typing import Dict, List, Optional, Tuple, Any
import os
import sys
def export_results_to_csv(explanations: List[Dict[str, Any]], df: pd.DataFrame, csv_path: str):
"""
Export the comprehensive scores, explanations, and the original data to a CSV file.
Args:
explanations: List of dictionaries containing explanations for each project.
df: The original DataFrame with the comprehensive scores added.
csv_path: The path to the CSV file where the results will be saved.
"""
# Create a list to hold the data for the CSV
data = []
# Iterate through each row in the DataFrame and its corresponding explanation
for index, row in df.iterrows():
# Get the explanation for the current row
explanation = explanations[index]
# Extract the comprehensive score
comprehensive_score = explanation["comprehensive_score"]
# Extract individual scores and methods
stability_score = explanation["stability"]["stability_score"]
stability_method = explanation["stability"]["method"]
revenue_diversification_score = explanation["revenue_diversification"]["diversification_score"]
revenue_diversification_method = explanation["revenue_diversification"]["method_used"]
user_efficiency_score = explanation["user_efficiency"]["score"]
user_efficiency_method = explanation["user_efficiency"]["method"]
sustainability_score = explanation["sustainability"]["score"]
sustainability_method = explanation["sustainability"]["method"]
transaction_activity_score = explanation["transaction_activity"]["score"]
transaction_activity_method = explanation["transaction_activity"]["method"]
# Create a dictionary for the current row
row_data = {
"Project": row["Project"],
"Market sector": row["Market sector"],
"Comprehensive Score": comprehensive_score,
"Stability Score": stability_score,
"Stability Method": stability_method,
"Revenue Diversification Score": revenue_diversification_score,
"Revenue Diversification Method": revenue_diversification_method,
"User Efficiency Score": user_efficiency_score,
"User Efficiency Method": user_efficiency_method,
"Sustainability Score": sustainability_score,
"Sustainability Method": sustainability_method,
"Transaction Activity Score": transaction_activity_score,
"Transaction Activity Method": transaction_activity_method,
}
# Add the row data to the list
data.append(row_data)
# Create a DataFrame from the list of dictionaries
results_df = pd.DataFrame(data)
# Save the DataFrame to a CSV file
results_df.to_csv(csv_path, index=False)
print(f"Results exported to {csv_path}")