如何根据三列中的值选择数据框中的行?

时间:2021-11-18 01:37:57

I have a dataframe with more than 1000 rows, and three columns with different values (integers). I would like to select rows, in which the values of three columns are within 2-folds or less of each other. I have tried this:

我有一个超过1000行的数据帧,以及三个具有不同值(整数)的列。我想选择行,其中三列的值在彼此的2倍或更小之内。我试过这个:

df = df[(df['B'] >  | < | == 2 * df['D']) & (df['B'] > | < | == 2 * df['F'])] 

which it did not work! I am new to Pandas.

它不起作用!我是熊猫的新手。

1 个解决方案

#1


2  

Looks like you might want to try:

看起来您可能想尝试:

df = df[((df.B>df.D) & (df.B<df.D*2)) & ((df.B>df.F) & (df.B<df.F*2))]

#1


2  

Looks like you might want to try:

看起来您可能想尝试:

df = df[((df.B>df.D) & (df.B<df.D*2)) & ((df.B>df.F) & (df.B<df.F*2))]