如何在 graphlab 中将日期从 unix 时间戳转换为人类可读格式 (python 2.7)

How to convert date from unix timestamps to human readable format in graphlab (python 2.7)

我正在处理 34gb 的大文本文件。我已经使用 graphlab create 成功解析了文件。数据集中有一列关于日期。日期以 unix 时间戳显示。如何将输入文件(转换为 SFrame)中的 UNIX 时间戳转换为人类可读格式?

有点古怪,但您可以将 unix 时间戳列强制转换为类型 "datetime.datetime"(前提是您导入了日期时间)。

此代码:

import graphlab as gl
import datetime as dt
sf = gl.SFrame({'a':[1,2,3]})
sf['a'] = sf['a'].astype(dt.datetime)

产生这个:

Columns:
    a       datetime

Rows: 3

Data:
+---------------------+
|          a          |
+---------------------+
| 1970-01-01 00:00:01 |
| 1970-01-01 00:00:02 |
| 1970-01-01 00:00:03 |
+---------------------+
[3 rows x 1 columns]