I want to subtract two columns in order to get the time, but my columns are object types.
This are my initial columns dtypes:
Column1 object
Column2 object
EVS_START object
Column3 object
time object
dtype: object
I changed EVS_START and time to datetime64[ns] like this:
df['time'] = pd.to_datetime(df['time'])
df['EVS_START'] = pd.to_datetime(df['EVS_START'])
I checked again with df.dtypes
and they were changed:
Column1 object
Column2 object
EVS_START datetime64[ns]
Column3 object
time datetime64[ns]
dtype: object
But when I am subtracting them I get TypeError: ufunc subtract cannot use operands with types dtype('<M8[ns]') and dtype('O')
df['Time_duration'] = df['time'] - df['EVS_START']
What am I doing wrong? I did something similar with a df and it worked fine I am using python 2.x