0

I have created an index with name 'dates' using pandas.date_range and I want to slice the 5th element from the Datetimeindex. How to slice the 5th element from it.

dates = pd.date_range(start = '1-Sep-2017',end = '15-Sep-2017')

DatetimeIndex(['2017-09-01', '2017-09-02', '2017-09-03', '2017-09-04',
               '2017-09-05', '2017-09-06', '2017-09-07', '2017-09-08',
               '2017-09-09', '2017-09-10', '2017-09-11', '2017-09-12',
               '2017-09-13', '2017-09-14', '2017-09-15'],
              dtype='datetime64[ns]', freq='D')
ALollz
  • 57,915
  • 7
  • 66
  • 89
  • 1
    `dates[4]` seems to do the trick? Or if it is the index of your DataFrame then `df.iloc[4]` – ALollz Sep 09 '19 at 19:15
  • Yes, Thank you. dates[4] is working and the output is 'Timestamp('2017-09-05 00:00:00', freq='D')' and when i use dates [4:5] then the output is 'DatetimeIndex(['2017-09-05'], dtype='datetime64[ns]', freq='D')'. – Shubham Arora Sep 09 '19 at 19:22
  • `dates [4:5]` gives you same output as an array as it excludes 5 but slices. – harvpan Sep 09 '19 at 19:24

0 Answers0