【发布时间】:2019-06-25 11:51:29
【问题描述】:
我目前正在尝试通过将日期转换为时间戳来在数据集中生成数字特征。如果在 Mac 上运行,它可以完美运行,在 Windows 上它会抛出:
OS Error: [Errno 22] Invalid argument
这可能是由于 Windows not supporting unix timestamps from before 1970-01-01。我的日期从 1955 年开始。这是我的代码:
import time
import datetime
current_timestamp = time.time()
df.loc[:, "FEATURE_num"] = df["FEATURE"].apply(lambda d: datetime.datetime.strptime(d, '%Y-%m-%d').timestamp() if isinstance(d, str) else current_timestamp)
我在某处看到有人建议使用datetime.timedelta(),但我不知道如何集成它。
【问题讨论】:
标签: python windows datetime timestamp