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
相关产品推荐
相关产品推荐

