简体   繁体   中英

Find points between two lines

I have a pandas dataframe with 2 columns and 1000 rows. The first column report some speed values, while the latter column some acceleration value.

I represented these points in a 'speed' vs 'acceleration' chart.

Now I want to plot just the points between two parallel lines r1 and r2 .

Which is the best way to filter the pandas dataframe values that satisfy the condiction to be between r1 and r2 ?

Here is my code:

import pandas as pd

#constants
m = -1
q1 = 10
q2 = 1 

df = pd.read_csv('my_file.csv', delimiter=';')
r1 = m*df['speed'] + q1
r2 = m*df['speed'] + q2

I want to keep just the rows of the dataframe df that satisfy the condition :

r1 < row < r2

Thus I will have a dataframe with the points between the two lines. Which is the best way to filter df

Thanks

You can use pandas.Series.between .

Assuming r1, r2, and row are acceleration,

df=df[df['acceleration'].between(m*df['speed']+q1, m*df['speed']+q2, inclusive=False)]

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