简体   繁体   中英

Dropping rows from pandas dataframe based on floatpoint range

Goal: remove all rows from series where value is within range -0.2 to 0.2. Datatype for values is float. Is there any way to do this that doesn't require converting the type?

Sample data:

index
2020-12-31 00:44:09 0.1515
2020-12-31 00:40:57 0.4404
2020-12-31 00:40:19 0.0000
2020-12-31 00:37:54 -0.2263
2020-12-31 00:23:38 -0.1234

Use Series.between with ~ for invert mask in boolean indexing if s is Series :

s = s[~s.between(-0.2, 0.2)]

If working with column col use:

df = df[~df['col'].between(-0.2, 0.2)]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM