title: Slope and Intercept of each cycle/season of a time series
body: <p>I have a time series with a cyclic/seasonal component. For each cycle, I am trying to figure out the slope and intercept of the highlighted section in red.</p>
  <p><a href="https://i.stack.imgur.com/kI2be.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kI2be.png" alt="enter image description here" /></a>
  <a href="https://i.stack.imgur.com/DMaNh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DMaNh.png" alt="enter image description here" /></a></p>
  <p>I have tried to define each cycle as 0, 1 .... n. But was unable to segment each cycle.</p>
  <pre class="lang-py prettyprint-override"><code>total = []
  for index, row in df.iterrows():
      total.append(row['top']) 
  
  cycle = []
  for i in range(len(total)):
      if total[i+1] &lt; total[i] - 4:
          cycle = cycle.append([i])
          
      else:
          cycle = i + 1
  </code></pre>