Is it possible to use cut on a collection of datetimes?
Question: Is it possible to use `pandas.cut` to make bins out of `datetime` stamps?

The following code:

    
    
    import pandas as pd
    import StringIO
    
    contenttext = """Time,Bid
    2014-03-05 21:56:05:924300,1.37275
    2014-03-05 21:56:05:924351,1.37272
    2014-03-05 21:56:06:421906,1.37275
    2014-03-05 21:56:06:421950,1.37272
    2014-03-05 21:56:06:920539,1.37275
    2014-03-05 21:56:06:920580,1.37272
    2014-03-05 21:56:09:071981,1.37275
    2014-03-05 21:56:09:072019,1.37272"""
    
    content = StringIO.StringIO(contenttext)
    df = pd.read_csv(content, header=0)
    df['Time'] = pd.to_datetime(df['Time'], format='%Y-%m-%d %H:%M:%S:%f')
    
    pd.cut(df['Time'], 5)
    

Throws the following error:

    
    
    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    <ipython-input-3-f5387a84c335> in <module>()
         16 df['Time'] = pd.to_datetime(df['Time'], format='%Y-%m-%d %H:%M:%S:%f')
         17 
    ---> 18 pd.cut(df['Time'], 5)
    
    /home/???????/sites/varsite/venv/local/lib/python2.7/site-packages/pandas/tools/tile.pyc in cut(x, bins, right, labels, retbins, precision, include_lowest)
         80         else:
         81             rng = (nanops.nanmin(x), nanops.nanmax(x))
    ---> 82         mn, mx = [mi + 0.0 for mi in rng]
         83 
         84         if mn == mx:  # adjust end points before binning
    
    TypeError: unsupported operand type(s) for +: 'Timestamp' and 'float'
    


Answer: Here is my work-around. You might need to change the code slightly to suit
your precision needs. I use date as an example below:

    
    
    # map dates to timedelta
    today=dt.date.today() 
    
    # x below is a timedelta,
    # use x.value below if you need more precision
    df['days']=map(lambda x : x.days, df.Time - today)
    
    pd.cut(df.days, bins=5)
    

Effectively you turn `datetime` or `date` into a numerical distance measure,
then cut/qcut it.

