title: Calculating the number of years in a pandas dataframe
body: <p>I've written a messy function which calculates the number of years in a dataframe based on it's length (assuming the dataframe has values for each day of the year). </p>
  
  <p>It works fine, but it's a lot of code that could be made much smarter (but I'm not sure how...)</p>
  
  <p>Here is the function, it only goes to 10 years, I want it to work for a dataset of any size. I could extend it further by copying and pasting and adding the totals up further, but there must be a smarter way to write this code.</p>
  
  <pre><code>def numyears(x):
      if len(x.index) &lt;= 366:
          return 1
      elif len(x.index) &lt;= 732:
          return 2
      elif len(x.index) &lt;= 1098:
          return 3
      elif len(x.index) &lt;= 1464:
          return 4
      elif len(x.index) &lt;= 1830:
          return 5
      elif len(x.index) &lt;= 2196:
          return 6
      elif len(x.index) &lt;= 2562:
          return 7
      elif len(x.index) &lt;= 2928:
          return 8
      elif len(x.index) &lt;= 3294:
          return 9
      elif len(x.index) &lt;= 3660:
          return 10
      else: 
          return 'ERROR'
  </code></pre>