使用pandas的日期间隔

时间:2016-07-05 10:20:44

标签: python datetime pandas

我有约会

                     used_at  active_seconds  buy  
0        2014-07-02 00:00:04               6    1  
1        2014-07-02 00:00:10               6    1  
2        2014-07-02 00:00:16               8    1  
3        2014-07-02 00:00:24               4    0  
4        2014-07-02 00:00:25              32    0  
5        2014-07-02 00:00:28               4    0  
6        2014-07-02 00:00:32             236    0  
7        2014-07-02 00:00:52              69    1  
8        2014-07-02 00:01:23               6    0  
9        2014-07-02 00:01:33               2    1  

我在此字符串之前尝试if buy == 1:打印数据,其中日期月份等于字符串(其中buy == 1)或month - 1。 我用

for i, (id, date, buy, url) in enumerate(zip(ids, dates, buys, urls)):
    if buys[i] == 1:
        buuy = str(id) + ' ' + str(date) + ' ' + str(buy) + ' ' + ":"
        print buuy
        print df.ix[dates[i-1]:dates[i].replace(month=date.month - 1, day=1)]

但它会返回KeyError: -1 怎么了?

0 个答案:

没有答案