'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
Solution 1:[1]
df.MinTime = df.MinTime.replace(microsecond=0)
Solution 2:[2]
I convert the timestamp into datetime format
df['MinTime']=pd.to_datetime(df['MinTime'])
df['MinTime'] = df['MinTime'].astype('datetime64[s]')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | richardec |
Solution 2 | zeerock |