当使用datetime对象数组进行初始化时,pandas.PeriodIndex导致ipython内核“意外死亡”

时间:2014-09-02 20:16:57

标签: python datetime pandas

以下是我可以重新创建此问题的方法:

In [2]: num = range(11)

In [3]: from netCDF4 import num2date

In [4]: time.units
Out[4]: u'days since 1859-12-01'

In [5]: time.calendar
Out[5]: u'360_day'

In [6]: dates = num2date(num, time.units, time.calendar)

In [7]: dates
Out[7]: 
array([1859-12-01 00:00:00, 1859-12-02 00:00:00, 1859-12-03 00:00:00,
       1859-12-04 00:00:00, 1859-12-05 00:00:00, 1859-12-06 00:00:00,
       1859-12-07 00:00:00, 1859-12-08 00:00:00, 1859-12-09 00:00:00,
       1859-12-10 00:00:00, 1859-12-11 00:00:00], dtype=object)

In [8]: import pandas as pd

In [9]: idx = pd.PeriodIndex(dates, freq='d')

In [10]: It seems the kernel died unexpectedly. Use 'Restart kernel' to continue using this console.
It seems the kernel died unexpectedly. Use 'Restart kernel' to continue using this console.
It seems the kernel died unexpectedly. Use 'Restart kernel' to continue using this console.
It seems the kernel died unexpectedly. Use 'Restart kernel' to continue using this console.

我有一个列表或数组(我试过两个)数值,表示给定日期与给定日历的天数(全部来自包含气候模型数据的netCDF4文件)。

首先,我使用netCDF4.num2date将数值数据转换为日期时间对象数组,如图所示。接下来,我使用pandas.PeriodIndex以每日频率加载日期。在此之后不久,我的内核就死了。我已经尝试了很多次这个问题对我来说是非常可重复的。关于这个问题的原因是什么或者如何减轻这个问题的任何想法都将非常感激。

编辑:问题源于这样一个事实,即我在num2date中使用了不规则的日历,这违反了pandas.PeriodIndex需要定期间隔的事实

0 个答案:

没有答案