简体   繁体   English

用条件计算总值

[英]calculate total value with condition

I am a newbie with pandas and numpy.我是 pandas 和 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']由于我的项目有超过一百万张票,我使用这个 function 返回值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我期待收到大家的来信

Your code needs a small fix.您的代码需要一个小修复。 You can use the following code instead.您可以改用以下代码。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM