且构网

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

如何在 pandas 数据框列中选择一系列值?

更新时间:2022-12-12 12:00:27

使用 betweeninclusive=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)