Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.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
Pandas 根据多列的条件从熊猫中删除/选择行_Pandas_Dataframe - Fatal编程技术网

Pandas 根据多列的条件从熊猫中删除/选择行

Pandas 根据多列的条件从熊猫中删除/选择行,pandas,dataframe,Pandas,Dataframe,从数据帧中,我需要根据应用于数据帧的两列的条件删除特定行 数据帧是 0 1 2 3 0 -0.225730 -1.376075 0.187749 0.763307 1 0.031392 0.752496 -1.504769 -1.247581 2 -0.442992 -0.323782 -0.710859 -0.502574 3 -0.948055 -0.224910 -1.337001 3.328741 4 1.8

从数据帧中,我需要根据应用于数据帧的两列的条件删除特定行

数据帧是

          0         1         2         3
0 -0.225730 -1.376075  0.187749  0.763307
1  0.031392  0.752496 -1.504769 -1.247581
2 -0.442992 -0.323782 -0.710859 -0.502574
3 -0.948055 -0.224910 -1.337001  3.328741
4  1.879985 -0.968238  1.229118 -1.044477
5  0.440025 -0.809856 -0.336522  0.787792
6  1.499040  0.195022  0.387194  0.952725
7 -0.923592 -1.394025 -0.623201 -0.738013
我需要删除
列1
列2
之间的差异小于阈值
t
的一些行

abs(column1.iloc[index]-column2.iloc[index]) < t
abs(column1.iloc[index]-column2.iloc[index])
我见过一些例子,其中条件单独应用于列值,但没有发现任何根据应用于多列的条件删除行的情况。

首先选择列作为位置,减去,获取,通过阈值与
反向
操作器类似的
=
进行比较,并通过以下方式进行过滤:

如果需要按名称选择列,请在此处
0
1

df = df[(df[0]-df[1]).abs() >= t]
df = df[(df[0]-df[1]).abs() >= t]