You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pandas DateTimeArray 获取第一个元素的方法是什么?

你可以直接通过下标索引取值,和常规序列的取值逻辑一致,第一个元素对应下标为0:

# 取DateTimeArray的第一个元素
first_val = dta[0]

执行后得到的结果是pandas的Timestamp类型:Timestamp('2015-01-01 00:00:00')。如果需要转为Python原生的datetime对象,可以额外调用to_pydatetime()方法:

first_py_datetime = dta[0].to_pydatetime()

内容的提问来源于stack exchange,提问作者Frederick Ollinger

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.10 07:42:03