[Python] calculating First time right (%) using call logs dataset from a contact center

Discussão em 'Python' iniciado por Stack, Maio 5, 2025.

  1. Stack

    Stack Membro Participativo

    I am calculating the First Time Resolution (FTR) percentage from call logs using the following Python code with pandas and numpy. When I run the code on one CSV file (calls_logs_cleaned_2025-05-02.csv), I get an FTR7% of approximately 63.8%. However, when I run the same code on a different CSV file (only the filename changed), the FTR7% drops significantly to around 39.8%.

    The main difference between the two files is that the second file contains an additional column L2 with some valid values filled for certain L1 categories, whereas in the first file, the L2 column exists but is completely blank. Apart from this, the files are essentially the same.

    Since the FTR calculation does not depend on the L1 or L2 columns at all, I am confused why the overall FTR percentage drops so much when using the second file.

    The csv has the following columns - customer_account_no , agent_id, agent_name, start_time, l1_intent, l2_intent

    Here's what i wrote in python

    import pandas as pd
    import numpy as np

    # Loading data
    df = pd.read_csv('calls_logs_cleaned_2025-05-02.csv')

    # Converting start_time to datetime
    df['start_time'] = pd.to_datetime(df['start_time'], format='mixed', dayfirst=True)

    # Sorting data by customer and time
    df = df.sort_values(by=['customer_account_no', 'start_time']).reset_index(drop=True)

    # Function to calculate FTR7 and FTR14
    def calculate_ftr(group):
    times = group['start_time'].values.astype('datetime64[ns]')
    n = len(times)
    ftr7, ftr14 = np.ones(n, dtype=int), np.ones(n, dtype=int)

    for i in range(1, n):
    current_time = times

    # Check if there is a previous call within 7 days
    left_bound_7 = current_time - np.timedelta64(7, 'D')
    idx_7 = np.searchsorted(times[:i], left_bound_7, side='right')
    ftr7 = 0 if idx_7 < i else 1

    # Check if there is a previous call within 14 days
    left_bound_14 = current_time - np.timedelta64(14, 'D')
    idx_14 = np.searchsorted(times[:i], left_bound_14, side='right')
    ftr14 = 0 if idx_14 < i else 1

    return pd.DataFrame({'FTR7': ftr7, 'FTR14': ftr14}, index=group.index)

    # Applying function per customer group
    df[['FTR7', 'FTR14']] = df.groupby('customer_account_no', group_keys=False).apply(calculate_ftr)

    # Calculate overall percentages
    ftr7_percent = df['FTR7'].mean() * 100
    ftr14_percent = df['FTR14'].mean() * 100

    print(f"FTR7%: {ftr7_percent:.1f}%")
    print(f"FTR14%: {ftr14_percent:.1f}%")



    Since the L1 and L2 columns are not used in the FTR calculation, I expected the FTR percentages to be roughly the same for both files.

    Question:


    1. Why does the FTR7% drop from ~63.8% to ~39.8% when using the second file that has valid L2 values?


    2. Could the presence of values in the L2 column affect the calculation even though the code does not explicitly use it?


    3. What should I check or debug to understand this discrepancy?

    Any insights or suggestions would be greatly appreciated!

    Continue reading...

Compartilhe esta Página