Q:

Pandas convert datatime format

I have a pandas dataframe with a column of datetime object with the following format: 
df['TIME_M']=pd.to_datetime(df['TIME_M'],format='%Y%m%d %H:%M:%S.%f')

However, at the same time, I also want a column of datetime with the following format (without the %f): 
%Y%m%d %H:%M:%S

Can I covert from the datetime object %s to the one without %s in a fast way? 
Currently I am using the following code: 
df['TIME_S']=df.TIME_M.map(lambda t:t.strftime('%Y%m%d %H:%M:%S'))

However, it seems that converting to string is a rather slow operation for pandas. I was wondering if there is a fast way to make the conversion, while keeping the output of the conversion as a datetime object? 
P.S. Assume that I already have df['TIME_M'] in format %Y%m%d %H:%M:%S.%f 

A:

First if need datetimes format is a bif different like need - YYYY-MM-DD HH:MM:SS.
If need datetimes without %f add floor:
df['TIME_M'] = pd.to_datetime(df['TIME_M'], format='%Y%m%d %H:%M:%S.%f').dt.floor('s')
#if datetimes column
#df['TIME_M'] = df['TIME_M'].dt.floor('s')

Or convert to numpy values ant then seconds:
df['TIME_M'] = pd.to_datetime(df['TIME_M'],format='%Y%m%d %H:%M:%S.%f').values.astype('datetime64[s]')
#if datetimes column
#df['TIME_M'] = df['TIME_M'].values.astype('datetime64[s]')

Or split in list comprehension:
df['TIME_M'] = pd.to_datetime([x.split('.')[0] for x in df['TIME_M']], format='%Y%m%d %H:%M:%S')

Timings in sample data:
N = 100000
df = pd.DataFrame({'TIME_M':['20190913 04:04:20'] * N})
df['TIME_M'] +=  ['.{}'.format(x) for x in range(1, len(df)+1)] 

df['TIME_M1'] = pd.to_datetime(df['TIME_M'],format='%Y%m%d %H:%M:%S.%f').dt.floor('s')
df['TIME_M2'] = pd.to_datetime([x.split('.')[0] for x in df['TIME_M']], format='%Y%m%d %H:%M:%S')
df['TIME_M3'] = pd.to_datetime(df['TIME_M'],format='%Y%m%d %H:%M:%S.%f').values.astype('datetime64[s]')

#print (df)

In [180]: %timeit df['TIME_M3'] = pd.to_datetime(df['TIME_M'],format='%Y%m%d %H:%M:%S.%f').values.astype('datetime64[s]')
28.2 ms ± 358 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)

In [181]: %timeit df['TIME_M1'] = pd.to_datetime(df['TIME_M'],format='%Y%m%d %H:%M:%S.%f').dt.floor('s')
28.7 ms ± 208 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)

In [182]: %timeit df['TIME_M2'] = pd.to_datetime([x.split('.')[0] for x in df['TIME_M']], format='%Y%m%d %H:%M:%S')
69 ms ± 1.81 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)

Thanks for another 2 solutions, @Anton vBR:
In [187]: %timeit df['TIME_M4'] = pd.to_datetime(df['TIME_M'].str[:17], format='%Y%m%d %H:%M:%S')
58 ms ± 709 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)

In [188]: %timeit df['TIME_M5'] = pd.to_datetime([x[:17] for x in df['TIME_M']], format='%Y%m%d %H:%M:%S')
45.6 ms ± 536 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)

