Skip to content

Instantly share code, notes, and snippets.

@u1and0
Created September 4, 2016 08:59
Show Gist options
  • Save u1and0/c8890bd548afe58951c13c9a29688264 to your computer and use it in GitHub Desktop.
Save u1and0/c8890bd548afe58951c13c9a29688264 to your computer and use it in GitHub Desktop.
pandas Timestampとdate_rangeの使い方 ref: http://qiita.com/u1and0/items/ed37fa4571f327b897e0
import pandas as pd
a=pd.Timestamp('2016-2-1')
# [Out]# Timestamp('2016-02-01 00:00:00')
b=pd.Timestamp('20160301')
# [Out]# Timestamp('2016-03-01 00:00:00')
pd.Timestamp('160301')
# [Out]# Timestamp('2001-03-16 00:00:00')
pd.date_range('20160201','20160301')
# [Out]# DatetimeIndex(['2016-02-01', '2016-02-02', '2016-02-03', '2016-02-04',
# [Out]# '2016-02-05', '2016-02-06', '2016-02-07', '2016-02-08',
# [Out]# '2016-02-09', '2016-02-10', '2016-02-11', '2016-02-12',
# [Out]# '2016-02-13', '2016-02-14', '2016-02-15', '2016-02-16',
# [Out]# '2016-02-17', '2016-02-18', '2016-02-19', '2016-02-20',
# [Out]# '2016-02-21', '2016-02-22', '2016-02-23', '2016-02-24',
# [Out]# '2016-02-25', '2016-02-26', '2016-02-27', '2016-02-28',
# [Out]# '2016-02-29', '2016-03-01'],
# [Out]# dtype='datetime64[ns]', freq='D')
pd.date_range('2014-11-01 10:00',periods=20,freq='H')
# [Out]# DatetimeIndex(['2014-11-01 10:00:00', '2014-11-01 11:00:00',
# [Out]# '2014-11-01 12:00:00', '2014-11-01 13:00:00',
# [Out]# '2014-11-01 14:00:00', '2014-11-01 15:00:00',
# [Out]# '2014-11-01 16:00:00', '2014-11-01 17:00:00',
# [Out]# '2014-11-01 18:00:00', '2014-11-01 19:00:00',
# [Out]# '2014-11-01 20:00:00', '2014-11-01 21:00:00',
# [Out]# '2014-11-01 22:00:00', '2014-11-01 23:00:00',
# [Out]# '2014-11-02 00:00:00', '2014-11-02 01:00:00',
# [Out]# '2014-11-02 02:00:00', '2014-11-02 03:00:00',
# [Out]# '2014-11-02 04:00:00', '2014-11-02 05:00:00'],
# [Out]# dtype='datetime64[ns]', freq='H')
pd.date_range('2014-11-01 10:00','2014-11-02 10:00',freq='H')
# [Out]# DatetimeIndex(['2014-11-01 10:00:00', '2014-11-01 11:00:00',
# [Out]# '2014-11-01 12:00:00', '2014-11-01 13:00:00',
# [Out]# '2014-11-01 14:00:00', '2014-11-01 15:00:00',
# [Out]# '2014-11-01 16:00:00', '2014-11-01 17:00:00',
# [Out]# '2014-11-01 18:00:00', '2014-11-01 19:00:00',
# [Out]# '2014-11-01 20:00:00', '2014-11-01 21:00:00',
# [Out]# '2014-11-01 22:00:00', '2014-11-01 23:00:00',
# [Out]# '2014-11-02 00:00:00', '2014-11-02 01:00:00',
# [Out]# '2014-11-02 02:00:00', '2014-11-02 03:00:00',
# [Out]# '2014-11-02 04:00:00', '2014-11-02 05:00:00',
# [Out]# '2014-11-02 06:00:00', '2014-11-02 07:00:00',
# [Out]# '2014-11-02 08:00:00', '2014-11-02 09:00:00',
# [Out]# '2014-11-02 10:00:00'],
# [Out]# dtype='datetime64[ns]', freq='H')
d.date_range('2014-11-01 10:00','2014-11-02 10:00',freq='2H')
# [Out]# DatetimeIndex(['2014-11-01 10:00:00', '2014-11-01 12:00:00',
# [Out]# '2014-11-01 14:00:00', '2014-11-01 16:00:00',
# [Out]# '2014-11-01 18:00:00', '2014-11-01 20:00:00',
# [Out]# '2014-11-01 22:00:00', '2014-11-02 00:00:00',
# [Out]# '2014-11-02 02:00:00', '2014-11-02 04:00:00',
# [Out]# '2014-11-02 06:00:00', '2014-11-02 08:00:00',
# [Out]# '2014-11-02 10:00:00'],
# [Out]# dtype='datetime64[ns]', freq='2H')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment