我有一个dataframe
列,用于说明需要转换为timestamp
的日期。现在的数据如下:
6 1970/01/01 01:00:12.273928
7 1970/01/01 01:00:12.459902
8 1970/01/01 01:00:12.569948
11 1970/01/01 01:00:14.292992
13 1970/01/01 01:00:14.825224
我尝试了以下
st = pd.to_datetime(df['StartTime'])
timestamp = datetime.timestamp(st)
print("timestamp =", timestamp)
但收到此错误
TypeError: descriptor 'timestamp' requires a 'datetime.datetime' object but received a 'Series'
有什么办法可以解决这个问题吗?
答案 0 :(得分:0)
您可以使用Apply。 St是一个序列,因此不能直接传递给timestamp函数。您需要将timestamp函数应用于系列元素。
st.apply(datetime.timestamp)
6 1.580998e+09
7 1.580998e+09
8 1.580998e+09
11 1.580998e+09
13 1.580998e+09
Name: StartTime, dtype: float64