简体   繁体   English

从pandas系列中提取datetime obj值(单行)

[英]extract datetime obj value from pandas Series (single row)

I have same issue as describe here link but this time with a datetime object. 我有与此处描述链接相同的问题,但是这次有一个datetime对象。

Using .values converts the datetime object to something like 2011-02-28T19:00:00.000000000-0500 . 使用.values会将datetime对象转换为类似2011-02-28T19:00:00.000000000-0500

Prior to the conversion the datetime was 2011-03-01 转换之前的日期时间为2011-03-01

What is the proper way to do what I want to do? 做我想做的事的正确方法是什么?

由于高精度的datetime64的[NS]值,如果你只是对日期感兴趣的话可以calll dt.date之前调用.values

p0_cost = (cost_df['price1'][cost_df['date']==p0] - cost_df['price2'][cost_df['date']==p0]).dt.date.values[0]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM