I would like to put a Pandas Data Frame column into datetime
format from datetime64
. This works on an an individual basis. In particular the following works fine:
t = dt['time'].values[0]
datetime.utcfromtimestamp(t.astype(int)/1000000000)
However, when I try to do this to the entire column
dt['datetime'] = dt['time'].apply(lambda x: datetime.utcfromtimestamp(x.astype(int)/1000000000))
I get the following error:
pandas/src/inference.pyx in pandas.lib.map_infer (pandas/lib.c:62578)()
<ipython-input-26-5950d82979b4> in <lambda>(x)
1 print(type(dt['time'].values[0]))
2
----> 3 dt['datetime'] = dt['time'].apply(lambda x: datetime.utcfromtimestamp(x.astype(int)/1000000000))
4 t = dt['time'].values[0]
5 print(t)
AttributeError: 'Timestamp' object has no attribute 'astype'
What am I doing wrong? How can I convert my column to datetime
and/or make a new column in datetime
format?
Here is the info for the dataframe: