Pandas set_index does not set the index

set_index is not inplace (unless you pass inplace=True). otherwise all correct

In [7]: df = df.set_index(pd.DatetimeIndex(df['b']))

In [8]: df
Out[8]: 
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 100 entries, 2013-06-14 09:10:23.523845 to 2013-06-14 10:12:51.650043
Data columns (total 2 columns):
b    100  non-null values
c    100  non-null values
dtypes: datetime64[ns](1), int64(1)

also as a FYI, in forthcoming 0.12 release (next week),
you can pass unit=us to specify units of microseconds since epoch

In [13]: pd.to_datetime(a,unit="us")
Out[13]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-06-14 13:10:23.523845, ..., 2013-06-14 14:12:51.650043]
Length: 100, Freq: None, Timezone: None

Leave a Comment