python date api

In [11]: import pandas as pd
 
In [12]: pd.date_range(start='20170101',end='20170110')
Out[12]:
DatetimeIndex(['2017-01-01', '2017-01-02', '2017-01-03', '2017-01-04',
               '2017-01-05', '2017-01-06', '2017-01-07', '2017-01-08',
               '2017-01-09', '2017-01-10'],
              dtype='datetime64[ns]', freq='D')
 
In [13]: pd.date_range(start='20170101',periods=10)
Out[13]:
DatetimeIndex(['2017-01-01', '2017-01-02', '2017-01-03', '2017-01-04',
               '2017-01-05', '2017-01-06', '2017-01-07', '2017-01-08',
               '2017-01-09', '2017-01-10'],
              dtype='datetime64[ns]', freq='D')
 
In [14]: pd.date_range(start='20170101',periods=10,freq='1D')
Out[14]:
DatetimeIndex(['2017-01-01', '2017-01-02', '2017-01-03', '2017-01-04',
               '2017-01-05', '2017-01-06', '2017-01-07', '2017-01-08',
               '2017-01-09', '2017-01-10'],
              dtype='datetime64[ns]', freq='D')
 
In [15]: pd.date_range(start='20170101',end='20170110',freq='3D',name='dt')
Out[15]: DatetimeIndex(['2017-01-01', '2017-01-04', '2017-01-07', '2017-01-10'],
 dtype='datetime64[ns]', name='dt', freq='3D')
 
In [16]: pd.date_range(start='2017-01-01 08:10:50',periods=10,freq='s',normaliz
    ...: e=True)
Out[16]:
DatetimeIndex(['2017-01-01 00:00:00', '2017-01-01 00:00:01',
               '2017-01-01 00:00:02', '2017-01-01 00:00:03',
               '2017-01-01 00:00:04', '2017-01-01 00:00:05',
               '2017-01-01 00:00:06', '2017-01-01 00:00:07',
               '2017-01-01 00:00:08', '2017-01-01 00:00:09'],
              dtype='datetime64[ns]', freq='S')
 
In [17]: pd.date_range(start='2017-01-01 08:10:50',end='2017-01-02 09:20:40',fr
    ...: eq='s',normalize=True)
Out[17]:
DatetimeIndex(['2017-01-01 00:00:00', '2017-01-01 00:00:01',
               '2017-01-01 00:00:02', '2017-01-01 00:00:03',
               '2017-01-01 00:00:04', '2017-01-01 00:00:05',
               '2017-01-01 00:00:06', '2017-01-01 00:00:07',
               '2017-01-01 00:00:08', '2017-01-01 00:00:09',
               ...
               '2017-01-01 23:59:51', '2017-01-01 23:59:52',
               '2017-01-01 23:59:53', '2017-01-01 23:59:54',
               '2017-01-01 23:59:55', '2017-01-01 23:59:56',
               '2017-01-01 23:59:57', '2017-01-01 23:59:58',
               '2017-01-01 23:59:59', '2017-01-02 00:00:00'],
              dtype='datetime64[ns]', length=86401, freq='S')
 
In [18]: pd.date_range(start='2017-01-01 08:10:50',periods=15,freq='s',normaliz
    ...: e=False)
Out[18]:
DatetimeIndex(['2017-01-01 08:10:50', '2017-01-01 08:10:51',
               '2017-01-01 08:10:52', '2017-01-01 08:10:53',
               '2017-01-01 08:10:54', '2017-01-01 08:10:55',
               '2017-01-01 08:10:56', '2017-01-01 08:10:57',
               '2017-01-01 08:10:58', '2017-01-01 08:10:59',
               '2017-01-01 08:11:00', '2017-01-01 08:11:01',
               '2017-01-01 08:11:02', '2017-01-01 08:11:03',
               '2017-01-01 08:11:04'],
              dtype='datetime64[ns]', freq='S')
 
In [19]: pd.date_range(start='20170101',end='20170110',freq='3D',closed='left')
    ...:
Out[19]: DatetimeIndex(['2017-01-01', '2017-01-04', '2017-01-07'], dtype='dateti
me64[ns]', freq='3D')
 
In [20]: pd.date_range(start='20170101',end='20170110',freq='3D',closed='right'
    ...: )
Out[20]: DatetimeIndex(['2017-01-04', '2017-01-07', '2017-01-10'], dtype='dateti
me64[ns]', freq='3D')


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值