I have two variables in the data set beginning date (format datetime64[ns]) and end date(format datetime64[ns]). I'm using following code to get the dates between beginning date and end date.
pd.date_range(start = data['beginning_date'], end = data['end_date'], freq = 'D')
but it's throwing following error.
cannot convert input to timestamp
why I'm getting above error. I tried changing as below, but it doesn't work.
pd.date_range(start = data['beginning_date'], end = data['end_date'], freq = 'D').astype('datetime')
and also i want each day as separate record, for example: beginning_date = 01APR2015 and end_date = 30APR2015, i want each day as separate record as below.
01APR2015
02APR2015 etc
How can I get it as a separate record?
Thanks in Advance.
Assuming you have the following DF:
In [30]: df
Out[30]:
beginning_date end_date
0 2013-12-22 2014-01-01
1 2009-12-14 2009-12-28
2 2010-12-31 2011-01-11
I guess you tried to use series instead of scalar values when calling pd.date_range()
method:
In [31]: pd.date_range(df.beginning_date, df.end_date)
...
skipped
...
TypeError: Cannot convert input to Timestamp
So try this instead:
In [32]: pd.date_range(df.beginning_date.min(), df.end_date.max())
Out[32]:
DatetimeIndex(['2009-12-14', '2009-12-15', '2009-12-16', '2009-12-17', '2009-12-18', '2009-12-19', '2009-12-20', '2009-12-21', '2009-12-22',
'2009-12-23',
...
'2013-12-23', '2013-12-24', '2013-12-25', '2013-12-26', '2013-12-27', '2013-12-28', '2013-12-29', '2013-12-30', '2013-12-31',
'2014-01-01'],
dtype='datetime64[ns]', length=1480, freq='D')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With