Untitled

 avatar
unknown
plain_text
21 days ago
1.8 kB
1
Indexable
import pandas as pd

def calculate_simple_health_score(df):
    """
    Calculate simple health scores for accounts using 1-2-3 scoring
    (1 = Low/Risk, 2 = Medium, 3 = High/Good)
    
    Expected columns:
    - account_name: Name of the account
    - monthly_job_posts: Number of job posts in current month
    - market_share: Share of job posts compared to total market (%)
    - budget_status: Budget utilization status
    """
    
    # Score job posting volume (1-3)
    df['job_post_score'] = pd.cut(
        df['monthly_job_posts'],
        bins=[-float('inf'), 20, 100, float('inf')],
        labels=[1, 2, 3]
    )
    
    # Score market share (1-3)
    df['market_share_score'] = pd.cut(
        df['market_share'],
        bins=[-float('inf'), 2, 10, float('inf')],
        labels=[1, 2, 3]
    )
    
    # Score budget status (1-3)
    df['budget_score'] = pd.cut(
        df['budget_status'],
        bins=[-float('inf'), 80, 95, float('inf')],
        labels=[3, 2, 1]  # Reversed because higher budget usage = higher risk
    )
    
    # Calculate total score (simple sum)
    df['total_score'] = df['job_post_score'] + df['market_share_score'] + df['budget_score']
    
    # Determine overall status
    df['status'] = pd.cut(
        df['total_score'],
        bins=[-float('inf'), 5, 7, float('inf')],
        labels=['Needs Attention', 'Monitor', 'Healthy']
    )
    
    return df

# Example usage with sample data
sample_data = {
    'account_name': ['Company A', 'Company B', 'Company C', 'Company D'],
    'monthly_job_posts': [150, 45, 80, 15],
    'market_share': [15, 4, 8, 1],
    'budget_status': [75, 85, 95, 60]
}

df = pd.DataFrame(sample_data)
scored_accounts = calculate_simple_health_score(df)
Editor is loading...
Leave a Comment