python - 将int数据类型转换为日期时间python
问题描述
我有一个包含用户 ID、评级和时间戳信息的数据集。原始数据集中的“时间戳”列是整数数据类型,我需要将其转换为日期数据类型。我的示例数据集如下:
| userId | rating | timestamp |
|--------|--------|-----------|
| 741 | 3.5 | 40006 |
| 742 | 3.5 | 41707 |
| 741 | 2.5 | 40279 |
| 743 | 3.5 | 41404 |
| 765 | 3.5 | 41684 |
| 800 | 2.5 | 42440 |
| 804 | 3 | 41540 |
| 802 | 4 | 41715 |
| 801 | 2.5 | 39916 |
| 741 | 3.5 | 41707 |
我尝试了下面的代码行,但所有时间戳都给了我一个日期“1970-01-01”。
df.loc[:,'timestamp'] = pd.to_datetime(df.loc[:,'timestamp'], format='%d%b%Y')
有人可以让我知道更正会是什么吗?
解决方案
推荐阅读
- angular - 如何在Angular材料中为文本输入着色
- ruby-on-rails - 如何计算多对多模型的特征向量?
- node.js - User.findAll 不是函数
- python - 为多个属性绘制图形 + matplotlib
- php - Codeigniter SaaS 应用程序 - cli cron 作业上的动态数据库选择
- html - 将div的高度设置为父div的底部
- r - 使用带有 JDBC 驱动程序的 R dbGetQuery 函数的多线程
- blazor - Blazor 中是否有与 Html.Raw 等效的内容?
- reactjs - 为什么我从 Marvel API 收到 InvalidCredentials 错误?
- sql - 显示员工姓名、休假、合格休假和百分比的查询