-1

I need to add a timestamp to a dataframe with the following settings:

from datetime import datetime
date_rng = pd.date_range(start='1/1/2020', end='1/21/2020', 
periods=len(df))

I would like to know how to discard the miliseconds terms since I need to convert to this format Jan 1, 1400 00:00:00 later in Quicksight. Thank you!

enter image description here

Itzy Death
  • 15
  • 2
  • 6

1 Answers1

0

You can use .floor('s'):

dummy example:

from datetime import datetime
date_rng = pd.date_range(start='1/1/2020', end='1/21/2020', periods=12)
date_rng.floor('s')

output:

DatetimeIndex(['2020-01-01 00:00:00', '2020-01-02 19:38:10',
               '2020-01-04 15:16:21', '2020-01-06 10:54:32',
               '2020-01-08 06:32:43', '2020-01-10 02:10:54',
               '2020-01-11 21:49:05', '2020-01-13 17:27:16',
               '2020-01-15 13:05:27', '2020-01-17 08:43:38',
               '2020-01-19 04:21:49', '2020-01-21 00:00:00'],
              dtype='datetime64[ns]', freq=None)
mozway
  • 194,879
  • 13
  • 39
  • 75