簡體   English   中英

使用 python 將 SQL 時間戳點轉換為日期時間

[英]Convert SQL timestamp point to datetime with python

我正在嘗試使用 python 將在 SQL 中創建的時間戳轉換為日期時間 object 或其他時間。

這是數據集

<bound method NDFrame.to_clipboard of                id                       user_id  sentiment  magnitude
created                                                              
1601820360     10  cPL1Fg7BqRXvSFKeU1mJT7KCCTq2       -0.1        0.1
1601820365     11  cPL1Fg7BqRXvSFKeU1mJT7KCCTq2       -0.8        0.8
1601900938     12  cPL1Fg7BqRXvSFKeU1mJT7KCCTq2       -0.2        0.2
1601900956     13  cPL1Fg7BqRXvSFKeU1mJT7KCCTq2       -0.2        0.2
1601900971     14  cPL1Fg7BqRXvSFKeU1mJT7KCCTq2        0.2        0.2
...           ...                           ...        ...        ...
1618553420  45024  cPL1Fg7BqRXvSFKeU1mJT7KCCTq2       -1.0        1.0
1618553422  45025  cPL1Fg7BqRXvSFKeU1mJT7KCCTq2       -1.0        1.0
1618553430  45026  cPL1Fg7BqRXvSFKeU1mJT7KCCTq2       -1.0        1.0
1618553432  45027  cPL1Fg7BqRXvSFKeU1mJT7KCCTq2       -1.0        1.0
1618883226  46022  cPL1Fg7BqRXvSFKeU1mJT7KCCTq2       -1.0        1.0

[10506 rows x 4 columns]>

created 是有問題的時間戳。

關於最佳方法的任何想法? 瀏覽 python 文檔我有點迷失了。 謝謝!

您可能需要使用單位作為秒。

pd.to_datetime(df.created, unit='s')

數據集中的樣本:

輸入:

    created     id
0   1601820360  10
1   1601820365  11

Output

     created    id
0   2020-10-04 14:06:00 10
1   2020-10-04 14:06:05 11

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM