Search code examples
pythonpandasanalytics

calculate total value with condition


I am a newbie with pandas and numpy. I have a question regarding to calculate total value with a condition from a different columns

Since I have over one million tickets for my project, I use this function to return the value data[data['FinalBatteryTestDecision'] == 'GOOD BATTERY'].sum()['ToolType']

However, the code takes forever to return the value. I wonder are there any methods to calculate the sum? I am looking forward to hearing from all


Solution

  • Your code needs a small fix. You can use the following code instead.

    data[data['FinalBatteryTestDecision'] == 'GOOD BATTERY']['ToolType'].sum()