Pandas: select 行,如果特定列满足特定条件

Pandas: select rows if a specific column satisfies a certain condition

说我有这个数据框 df:

    A   B   C
0   1   1   2
1   2   2   2
2   1   3   1
3   4   5   2

假设您想要 select 列 C>1 的所有行。如果我这样做:

newdf=df['C']>1

我在生成的 df 中只获得 TrueFalse。相反,在给出的例子中我想要这个结果:

    A   B   C
0   1   1   2
1   2   2   2
3   4   5   2

你会怎么做?您是否建议使用 iloc

使用boolean indexing:

newdf=df[df['C']>1]

使用query

df.query('C > 1')