Pandas: reindexing / "'Index' object has no attribute 'freq'"

1,943 views
Skip to first unread message

Will Furnass

unread,
May 3, 2012, 5:49:22 AM5/3/12
to pystat...@googlegroups.com
I've created a DataFrame using read_clipboard() (Pandas built from Git trunk) and am having problems reindexing unless I select rows using the [:] notation.  IIRC the index was defined using 'set_index("Timestamp")'. 

In [47]:
q_and_turb_df
df
Out[47]:
<class 'pandas.core.frame.DataFrame'>
Index: 61507 entries, 2010-01-31 15:30:00 to 2011-11-03 09:15:00
Data columns:
Q      61507  non-null values
NTU    61507  non-null values
dtypes: float64(2)

In [50]:
q_and_turb_df[:50000000]['Q'] < 14
df[:50000000]['Q'] < 14
Out[50]:
time
2010-01-31 15:30:00     True
2010-01-31 15:45:00     True
2010-01-31 16:00:00     True
2010-01-31 16:15:00    False
2010-01-31 16:30:00    False
<<snip; all fine here>>

In [51]:
q_and_turb_df['Q'] < 14
df['Q'] < 14
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/home/will/Dropbox/PhD/AI_general/Semblance/<ipython-input-51-2f53055c9488> in <module>()
----> 1 q_and_turb_df['Q'] < 14

/usr/lib/python2.7/dist-packages/IPython/core/displayhook.pyc in __call__(self, result)
    236             self.start_displayhook()
    237             self.write_output_prompt()
--> 238             format_dict = self.compute_format_data(result)
    239             self.write_format_data(format_dict)
    240             self.update_user_ns(result)

/usr/lib/python2.7/dist-packages/IPython/core/displayhook.pyc in compute_format_data(self, result)
    148             MIME type representation of the object.
    149         """
--> 150         return self.shell.display_formatter.format(result)
    151 
    152     def write_format_data(self, format_dict):

/usr/lib/python2.7/dist-packages/IPython/core/formatters.pyc in format(self, obj, include, exclude)
    124                     continue
    125             try:
--> 126                 data = formatter(obj)
    127             except:
    128                 # FIXME: log the exception


/usr/lib/python2.7/dist-packages/IPython/core/formatters.pyc in __call__(self, obj)
    445                 type_pprinters=self.type_printers,
    446                 deferred_pprinters=self.deferred_printers)
--> 447             printer.pretty(obj)
    448             printer.flush()
    449             return stream.getvalue()

/usr/lib/python2.7/dist-packages/IPython/lib/pretty.pyc in pretty(self, obj)
    352                 if callable(obj_class._repr_pretty_):
    353                     return obj_class._repr_pretty_(obj, self, cycle)
--> 354             return _default_pprint(obj, self, cycle)
    355         finally:
    356             self.end_group()

/usr/lib/python2.7/dist-packages/IPython/lib/pretty.pyc in _default_pprint(obj, p, cycle)
    472     if getattr(klass, '__repr__', None) not in _baseclass_reprs:
    473         # A user-provided repr.

--> 474         p.text(repr(obj))
    475         return
    476     p.begin_group(1, '<')

/usr/local/lib/python2.7/dist-packages/pandas-0.8.0.dev_1ea766c-py2.7-linux-x86_64.egg/pandas/core/series.pyc in __repr__(self)
    710                     else fmt.print_config.max_rows)
    711         if len(self.index) > max_rows:
--> 712             result = self._tidy_repr(min(30, max_rows - 4))
    713         elif len(self.index) > 0:
    714             result = self._get_repr(print_header=True,

/usr/local/lib/python2.7/dist-packages/pandas-0.8.0.dev_1ea766c-py2.7-linux-x86_64.egg/pandas/core/series.pyc in _tidy_repr(self, max_vals)
    728                                                   name=False)
    729         result = head + '\n...\n' + tail
--> 730         return '%s\n%s' % (result, self._repr_footer())
    731 
    732     def _repr_footer(self):

/usr/local/lib/python2.7/dist-packages/pandas-0.8.0.dev_1ea766c-py2.7-linux-x86_64.egg/pandas/core/series.pyc in _repr_footer(self)
   2551 
   2552     def _repr_footer(self):
-> 2553         if self.index.freq is not None:
   2554             freqstr = 'Freq: %s, ' % self.index.freqstr
   2555         else:

AttributeError: 'Index' object has no attribute 'freq'

Any thoughts?

Cheers,

Will

Chang She

unread,
May 3, 2012, 9:44:45 AM5/3/12
to pystat...@googlegroups.com
It looks like somehow your index is all datetime but is not a DatetimeIndex (which has the .freq property). I made a pandas github issue here: https://github.com/pydata/pandas/issues/1187. It should be an easy fix.

That being said, it actually looks like that DataFrame.set_index should do the right thing here. Would you mind putting more information on how to reproduce the error on the github issue linked to above?

Thanks,

Chang
Reply all
Reply to author
Forward
0 new messages