简体   繁体   中英

how to remove milliseconds or decimals in a specific dataframe column

I have 2 columns containing date and time(hr,min,seconds:milliseconds) How do I remove the milliseconds from only one of the column?

Name   MinTime                       MaxTime
John   2020-02-20 12:00:00.12345     2020-02-20 12:00:00.12345

Desired Output
Name   MinTime                       MaxTime
John   2020-02-20 12:00:00     2020-02-20 12:00:00.12345
df.MinTime = df.MinTime.replace(microsecond=0)

I convert the timestamp into datetime format

df['MinTime']=pd.to_datetime(df['MinTime'])
df['MinTime'] = df['MinTime'].astype('datetime64[s]')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM