1 回答
TA贡献1871条经验 获得超8个赞
这将做到这一点:
def first_der(df):
y = df.NREVS.values
x = df.cum_int.values
dy=np.diff(y,1)
dx=np.diff(x,1)
yfirst=dy/dx
return yfirst
def zero_runs(yfirst):
# Create an array that is 1 where a is 0, and pad each end with an extra 0.
iszero = np.concatenate(([0], np.equal(a, 0).view(np.int8), [0]))
absdiff = np.abs(np.diff(iszero))
# Runs start and end where absdiff is 1.
ranges = np.where(absdiff == 1)[0].reshape(-1,2)
return yind
def square_finder(yfirst, yind, df):
xmax = yind.shape[0] #max value in first position where y_first can be indexed
ymax = yind.shape[1] #max value in second position
thresh = 4
for i in range(0,xmax):
if yind[i][1] < len(yfirst):
if ((yfirst[yind[i][1]] > 5) | (yfirst[yind[i][1]] < -5)):
#if ((yfirst[yind[i-1][1]+1] > 3) | (yfirst[yind[i-1][1]+1] < -3)):
zeros = yind[i][1] - yind[i-1][1] - 2
if zeros >= thresh:
df['category'] = 'square'
else:
pass
else:
pass
else:
pass
return df
添加回答
举报