2013-12-13 8 views
6

서수 :이 기본적인 질문 추측팬더 날짜 열이 나는 날짜 열의 서수 하루 새로운 팬더 dataframe 열 만들려고 해요

import pandas as pd 
from datetime import datetime 

print df.ix[0:5] 
           date 
file        
gom3_197801.nc 2011-02-16 00:00:00 
gom3_197802.nc 2011-02-16 00:00:00 
gom3_197803.nc 2011-02-15 00:00:00 
gom3_197804.nc 2011-02-17 00:00:00 
gom3_197805.nc 2011-11-14 00:00:00 

df['date'][0].toordinal() 

Out[6]: 
734184 

df['date'].toordinal() 

--------------------------------------------------------------------------- 
AttributeError       Traceback (most recent call last) 
<ipython-input-7-dbfd5e8b60f0> in <module>() 
----> 1 df['date'].toordinal() 

AttributeError: 'Series' object has no attribute 'toordinal' 

을,하지만 난에 대한 문서를 읽고 싸워 왔어 지난 30 분.

데이터 프레임에 대해 서수 시간 열을 만들려면 어떻게해야합니까?

답변

12

사용 적용 :

df['date'].apply(lambda x: x.toordinal()) 
+0

곧,'안양 [ '날짜'] (datetime.toordinal)' – Zero

4

당신은 또한 map를 사용할 수 있습니다.

import datetime as dt 
df['date'].map(dt.datetime.toordinal) 
+0

timedata가로 반올림 적용 정수, 예를 들어'2015-12-08 12 : 13 : 46.343000'이지만 735940으로 반올림됩니다. 어떻게 십진수를 얻을 수 있습니까? – nandhos