【发布时间】:2018-11-06 05:24:06
【问题描述】:
我的数据格式如下:
Shop Date Produced Lost Output Signal
Cornerstop 01-01-2010 0 1 9 1
Cornerstop 01-01-2010 11 1 11 0
Cornerstop 01-01-2010 0 0 0 2
Cornerstop 01-01-2010 1 0 0 2
Cornerstop 01-01-2010 5 7 0 2
.
.
.
.
当 'Produced' 为 0 时,'Lost' 和 'Output' 的数据应该为 0,但那不是案子。我需要一种方法来找出何时不是这种情况(当 Produced 为 0 但 Lost、Output 或 Signal 中的任何一个都不为 0 时)。
制作一个计数器来计算这是真的与否的次数是我以前看到的数字:
counter = 0
for index, row in data.iterrows():
if row['Produced'] and row['Lost'] != 0:
counter += 1
else:
continue
我想确切地查看这些数据框中的哪些行(这是一个大集合),而且按每一行搜索几乎不是很有效。
有没有更好的方法可以做到这一点?
【问题讨论】:
标签: python python-3.x pandas dataframe if-statement