将datetime64转换为数字

时间:2018-05-30 00:27:41

标签: python pandas timestamp

如何将数据帧的timestamp列转换为数值?以下数据框中下面的时间列的数据类型' df'是&date;日期时间64'。

       Time          Count
2018-05-15 00:00:00    4
2018-05-15 00:15:00    1
2018-05-15 00:30:00    5
2018-05-15 00:45:00    6
2018-05-15 01:15:00    3
2018-05-15 01:30:00    4
2018-05-15 02:30:00    5
2018-05-15 02:45:00    3
2018-05-15 03:15:00    2
2018-05-15 03:30:00    5

1 个答案:

答案 0 :(得分:1)

使用to_numeric

pd.to_numeric(df.Time)
Out[218]: 
0    1526342400000000000
1    1526343300000000000
2    1526344200000000000
3    1526345100000000000
4    1526346900000000000
5    1526347800000000000
6    1526351400000000000
7    1526352300000000000
8    1526354100000000000
9    1526355000000000000
Name: Time, dtype: int64