且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在pandas数据框列中选择一个值范围?

更新时间:2022-12-12 12:09:17

使用 between inclusive=False用于严格的不等式:

Use between with inclusive=False for strict inequalities:

df['two'].between(-0.5, 0.5, inclusive=False)

inclusive参数确定是否包括端点(True:<=False:<).这适用于两个标志.如果您想要混合的不等式,则需要对其进行显式编码:

The inclusive parameter determines if the endpoints are included or not (True: <=, False: <). This applies to both signs. If you want mixed inequalities, you'll need to code them explicitly:

(df['two'] >= -0.5) & (df['two'] < 0.5)