Created
July 7, 2016 15:07
-
-
Save gthank/2a71c13cf616d5f7e9fd7fd616da255a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
def get_date(x): | |
"""Extract date from the provided timestamp. | |
Useful because the Pandas data model makes it hard to invoke | |
instance methods of values directly.""" | |
return x['Occurred Date or Date Range Start'].date() | |
seattle_data[['Occurred Date or Date Range Start', 'Offense Type']].groupby(get_date) | |
--------------------------------------------------------------------------- | |
TypeError Traceback (most recent call last) | |
<ipython-input-41-4b255aa153d2> in <module>() | |
9 return x['Occurred Date or Date Range Start'].date() | |
10 | |
---> 11 seattle_data[['Occurred Date or Date Range Start', 'Offense Type']].groupby(get_date) | |
/Users/hank/dev/.virtualenvs/datasci_assignment_six/lib/python3.5/site-packages/pandas/core/generic.py in groupby(self, by, axis, level, as_index, sort, group_keys, squeeze, **kwargs) | |
3776 return groupby(self, by=by, axis=axis, level=level, as_index=as_index, | |
3777 sort=sort, group_keys=group_keys, squeeze=squeeze, | |
-> 3778 **kwargs) | |
3779 | |
3780 def asfreq(self, freq, method=None, how=None, normalize=False): | |
/Users/hank/dev/.virtualenvs/datasci_assignment_six/lib/python3.5/site-packages/pandas/core/groupby.py in groupby(obj, by, **kwds) | |
1425 raise TypeError('invalid type: %s' % type(obj)) | |
1426 | |
-> 1427 return klass(obj, by, **kwds) | |
1428 | |
1429 | |
/Users/hank/dev/.virtualenvs/datasci_assignment_six/lib/python3.5/site-packages/pandas/core/groupby.py in __init__(self, obj, keys, axis, level, grouper, exclusions, selection, as_index, sort, group_keys, squeeze, **kwargs) | |
352 level=level, | |
353 sort=sort, | |
--> 354 mutated=self.mutated) | |
355 | |
356 self.obj = obj | |
/Users/hank/dev/.virtualenvs/datasci_assignment_six/lib/python3.5/site-packages/pandas/core/groupby.py in _get_grouper(obj, key, axis, level, sort, mutated) | |
2400 sort=sort, | |
2401 in_axis=in_axis) \ | |
-> 2402 if not isinstance(gpr, Grouping) else gpr | |
2403 | |
2404 groupings.append(ping) | |
/Users/hank/dev/.virtualenvs/datasci_assignment_six/lib/python3.5/site-packages/pandas/core/groupby.py in __init__(self, index, grouper, obj, name, level, sort, in_axis) | |
2213 t = self.name or str(type(self.grouper)) | |
2214 raise ValueError("Grouper for '%s' not 1-dimensional" % t) | |
-> 2215 self.grouper = self.index.map(self.grouper) | |
2216 if not (hasattr(self.grouper, "__len__") and | |
2217 len(self.grouper) == len(self.index)): | |
/Users/hank/dev/.virtualenvs/datasci_assignment_six/lib/python3.5/site-packages/pandas/indexes/base.py in map(self, mapper) | |
2238 applied : array | |
2239 """ | |
-> 2240 return self._arrmap(self.values, mapper) | |
2241 | |
2242 def isin(self, values, level=None): | |
pandas/src/generated.pyx in pandas.algos.arrmap_int64 (pandas/algos.c:94003)() | |
<ipython-input-41-4b255aa153d2> in get_date(x) | |
7 Useful because the Pandas data model makes it hard to invoke | |
8 instance methods of values directly.""" | |
----> 9 return x['Occurred Date or Date Range Start'].date() | |
10 | |
11 seattle_data[['Occurred Date or Date Range Start', 'Offense Type']].groupby(get_date) | |
TypeError: 'int' object is not subscriptable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment