Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用python根据另一列中的条件选择一列中的值?_Python_Pandas - Fatal编程技术网

如何使用python根据另一列中的条件选择一列中的值?

如何使用python根据另一列中的条件选择一列中的值?,python,pandas,Python,Pandas,如果column2比Column1中的当前值提前10分钟全部为零,是否有方法过滤行。在保持datetime索引的同时,如何执行此操作 2020-01-01 00:01:00 60 0 2020-01-01 00:02:00 70 0 2020-01-01 00:03:00 80 0 2020-01-01 00:04:00 70 0 2020-01-01 00:05:00 60 0 2020-01-01 00

如果column2比Column1中的当前值提前10分钟全部为零,是否有方法过滤行。在保持datetime索引的同时,如何执行此操作

2020-01-01 00:01:00     60      0
2020-01-01 00:02:00     70      0
2020-01-01 00:03:00     80      0
2020-01-01 00:04:00     70      0
2020-01-01 00:05:00     60      0
2020-01-01 00:06:00     60      0
2020-01-01 00:07:00     70      0
2020-01-01 00:08:00     80      0
2020-01-01 00:09:00     80      2
2020-01-01 00:10:00     80      0
2020-01-01 00:11:00     70      0
2020-01-01 00:12:00     70      0
2020-01-01 00:13:00     50      0
2020-01-01 00:14:00     50      0
2020-01-01 00:15:00     60      0
2020-01-01 00:16:00     60      0
2020-01-01 00:17:00     70      0
2020-01-01 00:18:00     70      0
2020-01-01 00:19:00     80      0
2020-01-01 00:20:00     80      0
2020-01-01 00:21:00     80      1
2020-01-01 00:22:00     90      2
预期产量

2020-01-01 00:19:00     80      0
2020-01-01 00:20:00     80      0

只是一个猜测,因为我不知道pandas,但假设它有点像SQL或linq或C中的可链接数据集-那么将表a与自身B链接/连接12分钟,按a的每一行分组,然后对B的第2列求和(如果只有正值),然后按和为0的列过滤SQL呢

结果报告A.column0、A.column1和SUMB.column2?

使用pandas.DataFrame.query


我想出来了。其实很简单

input['col3'] = input['col2'].rolling(10).sum()

output = input.loc[(input['col3'] == 0)]
input['col3'] = input['col2'].rolling(10).sum()

output = input.loc[(input['col3'] == 0)]