I don't think you can do this just with date_range
, but why not use numpy's linspace
:
In [11]: start = pd.Timestamp('2012-01-01')
In [12]: end = pd.Timestamp('2012-02-01')
In [13]: np.linspace(start.value, end.value, 10) # 10 dates inclusive
Out[13]:
array([ 1.32537600e+18, 1.32567360e+18, 1.32597120e+18,
1.32626880e+18, 1.32656640e+18, 1.32686400e+18,
1.32716160e+18, 1.32745920e+18, 1.32775680e+18,
1.32805440e+18])
In [14]: pd.to_datetime(np.linspace(start.value, end.value, 10))
Out[14]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2012-01-01 00:00:00, ..., 2012-02-01 00:00:00]
Length: 10, Freq: None, Timezone: None
You could pass this as a freq, but this may/will be inaccurate for times which don't evenly divide:
In [21]: (end - start)/ 9
Out[21]: datetime.timedelta(3, 38400)
In [22]: ((end - start)/ 9).total_seconds()
Out[22]: 297600.0
# Note: perhaps there's a better way to pass this as a freq?
In [23]: pd.date_range(start=start, end=end, freq='%iS' % ((end - start)/ 9).total_seconds())
Out[23]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2012-01-01 00:00:00, ..., 2012-02-01 00:00:00]
Length: 10, Freq: 297600S, Timezone: None