Last active
August 29, 2015 14:19
-
-
Save opotowsky/71d6c2ea168128fa6045 to your computer and use it in GitHub Desktop.
Trying to cut pandas series by even intervals (and sum those values)
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
For the following code snippet: | |
``` | |
u = pd.Series(u, index=m.index) | |
u = u.groupby(level=['TimeCreated']).sum() | |
u.name = 'FcoUMined' | |
# sum by years (12 time steps) | |
print u | |
u_year = u.groupby(pd.cut(u.index, np.arange(0, 12, 12)))['FcoUMined'].sum() | |
print u_year | |
``` | |
This error: | |
TimeCreated | |
50 19.609390 | |
68 6.733351 | |
81 6.733351 | |
95 6.733351 | |
110 6.733351 | |
124 6.733351 | |
138 6.733351 | |
152 6.733351 | |
166 6.733351 | |
180 6.733351 | |
194 6.733351 | |
208 6.733351 | |
222 6.733351 | |
236 6.733351 | |
250 6.733351 | |
264 6.733351 | |
278 6.733351 | |
292 6.733351 | |
306 6.733351 | |
320 6.733351 | |
334 6.733351 | |
348 6.733351 | |
362 6.733351 | |
376 6.733351 | |
390 4.961361 | |
404 6.733351 | |
418 5.552024 | |
432 6.733351 | |
446 6.142688 | |
460 6.733351 | |
474 6.733351 | |
488 4.961361 | |
502 6.733351 | |
516 5.552024 | |
530 6.733351 | |
Name: FcoUMined, dtype: float64 | |
--------------------------------------------------------------------------- | |
NotImplementedError Traceback (most recent call last) | |
<ipython-input-21-0ff429aa2b0f> in <module>() | |
29 return rtn | |
30 | |
---> 31 cym.exec_code("FcoUMined[:]", db) | |
/home/opotowsky/.local/lib/python2.7/site-packages/cymetric/execution.pyc in exec_code(code, db, write) | |
215 glb = {} | |
216 loc = ExecutionContext(evaler=evaler) | |
--> 217 exec(code, glb, loc) | |
<string> in <module>() | |
/home/opotowsky/.local/lib/python2.7/site-packages/cymetric/execution.pyc in __getitem__(self, key) | |
132 elif isinstance(k, str_types): | |
133 conds.append(parse_cond(k)) | |
--> 134 return self.evaler.eval(self.name, conds=conds) | |
135 | |
136 | |
/home/opotowsky/.local/lib/python2.7/site-packages/cymetric/evaluator.pyc in eval(self, metric, conds) | |
57 s = None if d is None else raw_to_series(d, dep[1], dep[2]) | |
58 series.append(s) | |
---> 59 raw = m(series=series, conds=conds, known_tables=self.known_tables) | |
60 if raw is None: | |
61 return raw | |
/home/opotowsky/.local/lib/python2.7/site-packages/cymetric/metrics.pyc in __call__(self, series, conds, known_tables, *args, **kwargs) | |
75 if self.name in known_tables: | |
76 return self.db.query(self.name, conds=conds) | |
---> 77 return f(series) | |
78 | |
79 Cls.__name__ = str(name) | |
<ipython-input-21-0ff429aa2b0f> in fco_u_mined(series) | |
24 # sum by years (12 time steps) | |
25 print u | |
---> 26 u_year = u.groupby(pd.cut(u.index, np.arange(0, 12, 12)))['FcoUMined'].sum() | |
27 print u_year | |
28 rtn = u_year.reset_index() | |
/usr/lib/python2.7/dist-packages/pandas/core/groupby.pyc in __getitem__(self, key) | |
489 | |
490 def __getitem__(self, key): | |
--> 491 raise NotImplementedError('Not implemented: %s' % key) | |
492 | |
493 def _make_wrapper(self, name): | |
NotImplementedError: Not implemented: FcoUMined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment