I'm using Python 2.7. The title provides context. I phrased the title in this specific way so people can query for this stack exchange question in the future. There is a plethora of documentation for this stuff using MATLAB, but this process is severely lacking for Scipy, NumPy, Pandas, matplotlib, etc.
Essentially, I have the following dataframe:
time amplitude
0 1.0 0.1
1 2.0 -0.3
2 3.0 1.4
3 4.0 4.2
4 5.0 -5.7
5 6.0 2.3
6 7.0 -0.2
7 8.0 -0.3
8 9.0 1.0
9 10.0 0.1
Now what I want to do is the following:
- in 5 second intervals, look for the max and min value
- record max and min value with the corresponding time value (i.e. for the above case, in the first 5 seconds, the max is 4.2 at 4 seconds and -5.7 at 5 seconds)
append values in appropriate place into the data frame i.e.
time amplitude upper lower 0 1.0 0.1 1 2.0 -0.3 2 3.0 1.4 3 4.0 4.2 4.2 4 5.0 -5.7 -5.7 5 6.0 2.3 2.3 6 7.0 -0.8 -0.8 7 8.0 -0.3 8 9.0 1.0 9 10.0 0.1
interpolate between max values and min values to flush out dataframe
plot amplitude column, upper column and lower column
I'm familiar enough with python/pandas and imagine the code looking something like the following:
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import scipy as scipy
time = [0,1,2,3,4,5,6,7,8,9]
amplitude = [0.1,-0.3,1.4,4.2,-5.7,2.3,-0.2,-0.3,1.0,0.1]
df = pd.DataFrame({'time': time, 'amplitude': amplitude}]
plt.plot(df['time'],df['amplitude])
for seconds in time:
if <interval == 5>:
max = []
time_max = []
min = []
time_min = []
max.append(df.max['amplitude'])
min.append(df.min['amplitude'])
time_max.append(<time value in interval>)
time_min.append(<time value in interval>)
<build another dataframe>
<concat to existing dataframe df>
<interpolate between values in column 'upper'>
<interpolate between values in column 'lower'>
any help is appreciated.
thank you.
~devin