2

I have a DatetimeIndex dataframe and I am trying to round the microseconds to centiseconds.
For instance, I have the following dataframe:

In [71]:df= pd.date_range('2017-7-7 02:03:04.000',periods=5,freq='50ms')

In [72]:df
Out[72]: 
DatetimeIndex(['2017-07-07 02:03:04', '2017-07-07 02:03:04.050000',
           '2017-07-07 02:03:04.100000', '2017-07-07 02:03:04.150000',
           '2017-07-07 02:03:04.200000'],
          dtype='datetime64[ns]', freq='50L')

and the expected output should be similar to this:

DatetimeIndex(['2017-07-07 02:03:04', '2017-07-07 02:03:04.05',
           '2017-07-07 02:03:04.10', '2017-07-07 02:03:04.15',
           '2017-07-07 02:03:04.20'],
          dtype='datetime64[ns]', freq='50L')

I can print the expected results, but I cannot change the dataframe. Is there any other more optimal way to achieve this? The method that I used is this:

for i in df:
    print i.strftime('%Y-%m-%d %H:%M:%S.'+ str(i.microsecond/10000))
Konkos
  • 21
  • 1

0 Answers0