Reputation: 55
For example lets say I have the following data set which goes on for 20,000 rows (large data set).
time velocity
0.000000 2.36949
0.005217 2.36169
0.010434 2.35677
0.015651 2.35299
0.020869 2.35015
I would want to take the second value in 'velocity' and subtract it from the first value. If the difference is less than say, 0.005, then continue to the third value.
And continue to take the difference between third and second value, but if difference is greater than 0.005, divide the difference of these two values by another value and store the result.
I would like to continue this process throughout the entire dataframe.
Ultimately I want to plot the 'delta values' which meet my condition versus the time at which they occur.
Any help is appreciated.
Upvotes: 2
Views: 49
Reputation: 323276
Do the diff
then with np.where
s=df.velocity.diff()
df['new']=np.where(s.abs()>0.005,s/value,s)
Upvotes: 5