【发布时间】:2019-06-28 01:49:12
【问题描述】:
我有几年的数据,比如(作为 pandas 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'
【问题讨论】:
-
你是如何安装 pandas 的,它的版本是多少?什么是解释器版本?
-
Linux CentO 中的 Pandas 0.24.0。使用 conda install 安装。 Conda 4.6.1 但它并不那么重要,因为它适用于相同条件下的另一个数据帧
-
请发布一个不会导致错误的数据框和导致错误的数据框的最小示例。另外,
import pandas as pd; print(pd.NaT)是否会为您打印NaT还是会导致异常? -
数据帧的每个部分都会导致此错误。 print(pd.NaT) 不会导致异常
-
那么,没人知道这个问题吗?源 CSV 文件具有 xxxx-xx-xx 格式的日期。我设法重新采样的源文件有 xxxx-xx-xx xx.xx.xx.xxx 时间。但是我改变了时间的格式。
标签: pandas resampling