Home > Net >  How to extract date time from dtype('<M8[ns]') in pandas?
How to extract date time from dtype('<M8[ns]') in pandas?

Time:11-30

my ots column has : 2021-04-03 14:01:22.791856 its dtype is dtype('<M8[ns]') how do I get only 2021-04-03 14:01:22 ?

CodePudding user response:

use this: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.dt.strftime.html

considering that is your time column in the pandas dataframe:

df['time'] = df['time'].dt.strftime('%Y-%m-%d %H:%M:%S')
  • Related