python - 使用python将SQL时间戳点转换为日期时间
问题描述
我正在尝试使用 python 将在 SQL 中创建的时间戳转换为 datetime 对象或 therabouts。
这是数据集
<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
输出
created id
0 2020-10-04 14:06:00 10
1 2020-10-04 14:06:05 11
推荐阅读
- mongodb - 带有 Socket.io 问题的实时天才聊天
- r - 如何识别所有行的至少一列中的值的 ID?
- java - 带有 Ajax 功能的 Spring Boot 错误“不支持请求方法'POST'”
- c++ - 递增 std::string::end() 迭代器是否未定义?
- c - 有没有更好的方法来检查这两个变量而不是四个 ifs?
- vb.net - 从 radiobuttonlist vb.net 更改样式并添加标签
- typescript - AWS CodeBuild tsc 错误 TS2307:找不到模块
- reactjs - 重复相同的输入不显示
- vba - 用实际图像替换图像文件名
- android - Xamarin Forms Android - 保存到文件