熊猫set_index不设置索引

熊猫set_index不设置索引,第1张

熊猫set_index不设置索引

set_index
没有就位(除非您通过
inplace=True
)。否则一切正确

In [7]: df = df.set_index(pd.DatetimeIndex(df['b']))In [8]: dfOut[8]: <class 'pandas.core.frame.Dataframe'>DatetimeIndex: 100 entries, 2013-06-14 09:10:23.523845 to 2013-06-14 10:12:51.650043Data columns (total 2 columns):b    100  non-null valuesc    100  non-null valuesdtypes: datetime64[ns](1), int64(1)

同样作为参考,在即将到来的0.12版本(下周)中,您可以传递

unit=us
以指定自纪元以来的微秒单位

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


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5630254.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存