3

I have several years of data like (as 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

Date is Index of type 'pandas.core.indexes.datetimes.DatetimeIndex'

df.resample('Y').sum() 

gives an error "cannot import name 'NaT'".

What is the source of the error? I tried to_datetime with format '%Y-%m-%d %H:%M:%S' but it doesn't help.

Full text of exception:

    ---------------------------------------------------------------------------
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'
Nikolay Yasinskiy
  • 227
  • 1
  • 2
  • 13
  • How did you install pandas and what is its version? What is the interpreter version? – Sasha Tsukanov Feb 04 '19 at 10:26
  • Pandas 0.24.0 in Linux CentOs. Installed with conda install. Conda 4.6.1 But it's not so important, as it worked for another dataframe in the same conditions – Nikolay Yasinskiy Feb 04 '19 at 10:32
  • 1
    Please post a minimal example of a dataframe which doesn't cause the error and the one which causes. Also, does `import pandas as pd; print(pd.NaT)` print `NaT` for your or does it cause an exception? – Sasha Tsukanov Feb 04 '19 at 12:34
  • every part of the dataframe causes this error. print(pd.NaT) does not cause an exception – Nikolay Yasinskiy Feb 04 '19 at 12:37
  • So, nobody knows this problem? The source CSV file has dates in xxxx-xx-xx format. The source file that I manage to resample has xxxx-xx-xx xx.xx.xx.xxx time. But I change the format of time. – Nikolay Yasinskiy Feb 05 '19 at 07:57
  • Well, df.groupby(df.index.to_period('Y')).mean() worked well for my task. But problem with resampling still persists. – Nikolay Yasinskiy Feb 05 '19 at 13:17

2 Answers2

0

I also have this problem, the environment is Linux Centos, but it works on my Macbook system. I don't know whether it's only occur on the Linux.

0

I had the same issue and found shutting down my instance, uninstalling, and reinstalling worked for me.

run in console

conda uninstall pandas

conda install pandas

(credit to this post)

ike
  • 342
  • 3
  • 17