As pointed out by @ user3735204, you can round the columns with:
df['datecol'] = df['datecol'].astype('datetime64[m]')
where the unit in square brackets can be:
Y[ear] M[month] D[ay], h[our], m[inute], s[econd]
You can also round to the nearest ( help ) by specifying the column as an index and using the round method (available in pandas 0.19.0)
df.index = pd.to_datetime(df['datecol']) df.index = df.index.round("S")
Example:
df = pd.DataFrame(data = tmpdata) df['datecol'] = df['datecol'].astype('datetime64[s]') print df['datecol'] 0 2016-10-05 05:37:42 1 2016-10-05 05:37:43 Name: datecol, dtype: datetime64[ns] df.index = pd.to_datetime(df['datecol']) df.index = df.index.round("S") print df.index DatetimeIndex(['2016-10-05 05:37:43', '2016-10-05 05:37:43'], dtype='datetime64[ns]', name=u'timestamp', freq=None)
source share