Peter
Peter

Reputation: 1128

Pandas timestamp doesn't play nicely with numpy datetime?

I'm just beginning to use pandas 0.9 and am seeing unexpected behavior with pandas timestamps. After setting an index with a datetime, the timeindex doesn't seem to correctly convert to anything else. I'm probably not using it correctly, so please set me straight:

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)

I would wouldn't expect anything with 1970 as a result of these operations. Thoughts?

Upvotes: 2

Views: 883

Answers (1)

Related Questions