그룹화 된 오브젝트의 절대 값 평균을 계산하고 싶습니다.groupby 오브젝트 팬더의 절대 값 평균
e.e.
grouped = df.groupby([pd.TimeGrouper(3MS)])
dct['x'] = grouped['profit'].agg('mean')/grouped['cost'].abs().agg('mean')
그러나 위의 코드는 오류가 발생합니다. 위의 코드에서 다양한 변형을 시도했지만 지금까지는 모두 오류가 발생했습니다.
이 작업을 수행하는 간단한 방법이 있어야합니다.
는업데이트 :
이 VI pd.TimeGrouper (3MS) 그룹화 된 dataframe입니다. 열 비용 1의 절대 값을 취한 다음 평균을 구합니다.
cost1 cost2 cost3 cost4
date
2016-03-31 -490.60 -118.10 -344.87 -91.44
2016-04-30 -188.74 -55.99 -259.23 -75.16
2016-05-31 -158.62 -43.58 -176.37 -21.98
나는
grouped['cost1'].abs().mean()
을하려고 노력하지만 난 가지고 : 당신이 SEREIS 객체에
.agg
를 사용할 수 없기 때문에
/Users/User1/anaconda/lib/python2.7/site-packages/pandas/core/groupby.pyc in __getattr__(self, attr)
493 return self[attr]
494 if hasattr(self.obj, attr):
--> 495 return self._make_wrapper(attr)
496
497 raise AttributeError("%r object has no attribute %r" %
/Users/User1/anaconda/lib/python2.7/site-packages/pandas/core/groupby.pyc in _make_wrapper(self, name)
507 "using the 'apply' method".format(kind, name,
508 type(self).__name__))
--> 509 raise AttributeError(msg)
510
511 # need to setup the selection
AttributeError: ("Cannot access callable attribute 'abs' of 'SeriesGroupBy' objects, try using the 'apply' method", u'occurred at index 0')
몇 가지 샘플 데이터를 게시 할 수 있으며 오류는 무엇입니까? 그렇지 않으면 우리는 여기서 무엇이 잘못되었는지를 추측합니다. – ako
내가 제안한 정보를 추가했습니다. 도움을 주셔서 감사합니다. – codingknob