什么是将时间戳转换为 int 的最常见方法

Whats is the most common way to convert a Timestamp to an int

我尝试了多种方法,但它们总是给我一个错误。我得到的最常见错误是:

AttributeError: 'Timestamp' object has no attribute 'astype'

这是我尝试转换元素的行:

df.index.map(lambda x: x - oneSec if (pandas.to_datetime(x).astype(int) / 10**9) % 1 else x)

我试过x.astype(int)x.to_datetime().astype(int)

我觉得这里很有必要用Index.where:

df = pd.DataFrame(index=(['2019-01-10 15:00:00','2019-01-10 15:00:01']))

df.index = pd.to_datetime(df.index)

mask = df.index.second == 1
print (mask)
[False  True]

df.index = df.index.where(~mask, df.index - pd.Timedelta(1, unit='s'))
    
print (df)
Empty DataFrame
Columns: []
Index: [2019-01-10 15:00:00, 2019-01-10 15:00:00]