title: Pythonic way to transform date vector into ranges?
body: <p>I have a pandas DataFrame with one row per day, and some boolean columns. I'd like to transform them into a DataFrame that holds the <em>ranges</em> where these columns are True.</p>
  
  <p>An example starting DF:</p>
  
  <pre><code>import pandas as pd
  
  t = True
  f = False
  
  df = pd.DataFrame(
      {'indic': [f, f, t, t, t, f, f, f, t, f, f, t, t, t, t]},
      index=pd.date_range("2018-01-01", "2018-01-15")
  )
  
  print(df)
  
              indic
  2018-01-01  False
  2018-01-02  False
  2018-01-03   True
  2018-01-04   True
  2018-01-05   True
  2018-01-06  False
  2018-01-07  False
  2018-01-08  False
  2018-01-09   True
  2018-01-10  False
  2018-01-11  False
  2018-01-12   True
  2018-01-13   True
  2018-01-14   True
  2018-01-15   True
  </code></pre>
  
  <p>This DataFrame's column is True from 2018-01-03 to 2018-01-05, then on 2018-01-09 (only one day), and then again from 2018-01-12 to 2018-01-15.</p>
  
  <p>The output I am looking for in this example is this DF (date objects instead of strings would be okay too, even preferred):</p>
  
  <pre><code>desired_result = pd.DataFrame({
      'from': ["2018-01-03", "2018-01-09", "2018-01-12"],
      'to': ["2018-01-05", "2018-01-09", "2018-01-15"]
  })
  
  print(desired_result)
  
           from          to
  0  2018-01-03  2018-01-05
  1  2018-01-09  2018-01-09
  2  2018-01-12  2018-01-15
  </code></pre>
  
  <p>As an extension, in a follow-up step I'd like this to work for multiple columns, e.g.:</p>
  
  <pre><code>df = pd.DataFrame(
      {
          'indic_A': [f, f, t, t, t, f, f, f, t, f, f, t, t, t, t],
          'indic_B': [f, f, f, f, f, f, f, f, t, t, t, t, t, f, f]
      },
      index=pd.date_range("2018-01-01", "2018-01-15")
  )
  
  desired_result = pd.DataFrame({
      'from': ["2018-01-03", "2018-01-09", "2018-01-12", "2018-01-09"],
      'to': ["2018-01-05", "2018-01-09", "2018-01-15", "2018-01-13"],
      'what': ["indic_A", "indic_A", "indic_A", "indic_B"]
  })
  
  print(desired_result)
  
           from          to     what
  0  2018-01-03  2018-01-05  indic_A
  1  2018-01-09  2018-01-09  indic_A
  2  2018-01-12  2018-01-15  indic_A
  3  2018-01-09  2018-01-13  indic_B
  </code></pre>
  
  <p>Is there a pythonic, elegant way to do this - maybe even a pandas function?</p>