我有几年的数据,例如(作为熊猫TimeSeries):
1997-04-02 0.0
1997-04-03 0.0
1997-04-04 2.0
1997-04-05 2.0
1997-04-06 0.0
1997-04-07 0.0
1997-04-08 0.0
日期是“ pandas.core.indexes.datetimes.DatetimeIndex”类型的索引
df.resample('Y').sum()
出现错误“无法导入名称'NaT'”。
错误的根源是什么?我尝试使用格式'%Y-%m-%d%H:%M:%S'的to_datetime,但这无济于事。
全文例外:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-342-df3b79446059> in <module>
12 globals()['df_'+col]=nm #.resample('M').sum()
13 df_dataKlin27417c=df_dataKlin27417.loc['1997-04-02':'1997-05-06']
---> 14 rex=df_dataKlin27417.resample('M').sum()
15 #rex
16 df_allst
~/anaconda3/lib/python3.6/site-packages/pandas/core/generic.py in resample(self, rule, how, axis, fill_method, closed, label, convention, kind, loffset, limit, base, on, level)
7102 Show which entries in a DataFrame are not NA.
7103
-> 7104 >>> df = pd.DataFrame({'age': [5, 6, np.NaN],
7105 ... 'born': [pd.NaT, pd.Timestamp('1939-05-27'),
7106 ... pd.Timestamp('1940-04-25')],
~/anaconda3/lib/python3.6/site-packages/pandas/core/resample.py in <module>
7
8 from pandas._libs import lib
----> 9 from pandas._libs.tslibs import NaT, Timestamp
10 from pandas._libs.tslibs.frequencies import is_subperiod, is_superperiod
11 from pandas._libs.tslibs.period import IncompatibleFrequency
ImportError: cannot import name 'NaT'
答案 0 :(得分:0)
我也有这个问题,环境是Linux Centos, 但它可以在我的Macbook系统上使用。 我不知道它是否仅出现在Linux上。
答案 1 :(得分:0)