in the chap03ex notebook, cell 3 fails when the _DictWrapper class updates data from a pandas Series when running with Python 2.7. The class uses the items() method, which is not present in the 0.20.3 Python 2.7 release of pandas.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-1500ad553f53> in <module>()
----> 1 hist = thinkstats2.Hist(live.birthwgt_lb, label='birthwgt_lb')
2 thinkplot.Hist(hist)
3 thinkplot.Config(xlabel='Birth weight (pounds)', ylabel='Count')
/Users/gbremer/projects/ThinkStats2/code/thinkstats2.pyc in __init__(self, obj, label)
153 self.d.update(obj.Items())
154 elif isinstance(obj, pandas.Series):
--> 155 self.d.update(obj.value_counts().items())
156 else:
157 # finally, treat it like a list
/Users/gbremer/anaconda/envs/thinkstats2-27/lib/python2.7/site-packages/pandas/core/generic.pyc in __getattr__(self, name)
3075 if (name in self._internal_names_set or name in self._metadata or
3076 name in self._accessors):
-> 3077 return object.__getattribute__(self, name)
3078 else:
3079 if name in self._info_axis:
AttributeError: 'Series' object has no attribute 'items'
The Series.value_counts() object, a Series instance, does have an iteritems() method which works.
The code works in Python 3.6 using both the items() and iteritems() method; items() and iteritems() are both implemented.
Looking at the pandas docs, items() and iteritems() are equivalent --
in the chap03ex notebook, cell 3 fails when the _DictWrapper class updates data from a pandas Series when running with Python 2.7. The class uses the items() method, which is not present in the 0.20.3 Python 2.7 release of pandas.
The code in cell 3 --
The exception --
The Series.value_counts() object, a Series instance, does have an iteritems() method which works.
The code works in Python 3.6 using both the items() and iteritems() method; items() and iteritems() are both implemented.
Looking at the pandas docs, items() and iteritems() are equivalent --
https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.html
items() | Lazily iterate over (index, value) tuples iteritems() | Lazily iterate over (index, value) tuples