我刚刚开始使用pandas 0.9并且看到了pandas时间戳的意外行为。使用日期时间设置索引后,timeindex似乎无法正确转换为其他任何内容。我可能没有正确使用它,所以请让我直截了当:
from pandas import *
import datetime
version.version
# 0.9.1
np.version.version
# 1.6.2
ndx = ['a','b','b']
date = [datetime.datetime(2013, 2, 16, 15, 0), datetime.datetime(2013, 2, 16, 11, 0),datetime.datetime(2013, 2, 16, 2, 0)]
vals = [1,2,3,]
df = DataFrame({'ndx':ndx,'date':date,'vals':vals})
df2=df.groupby(['ndx','date']).sum()
df2.index.get_level_values('date')
# array([1970-01-16 143:00:00, 1970-01-16 130:00:00, 1970-01-16 139:00:00], dtype=datetime64[ns])
df.set_index([ndx,date]).reset_index()['level_1'].unique() # fetch from index
# array([1970-01-16 143:00:00, 1970-01-16 139:00:00, 1970-01-16 130:00:00], dtype=datetime64[ns])
df.set_index([ndx,date]).reset_index()['date'].unique() # fetch from column
# array([2013-02-16 15:00:00, 2013-02-16 11:00:00, 2013-02-16 02:00:00], dtype=object)
由于这些操作,我不会指望1970年的任何事情。思考?
答案 0 :(得分:4)