我有一个函数ag-grid-react
,其中const $ = function(selector) {
if (!(this instanceof $)) {
return new $(selector);
};
this.el = document.querySelectorAll(selector);
};
$.prototype.css = function(obj) {
this.el.forEach(function(element) {
element.style[Object.keys(obj)[0]] = Object.values(obj);
});
};
$.prototype.click = function(callback) {
this.el.forEach(function(element) {
element.addEventListener('click', callback, false);
});
};
是f(a, b)
,它返回的a, b
pandas.Series
的长度与pandas.Series
和{{ 1}}。
现在我有两个系列c
和a
,它们具有相同的多重索引。 b
由许多小的A
组成。鉴于我无法使用B
直接计算结果。我想使用groupby来计算结果A, B
,并将它们连接在一起。
我应该怎么做?
样本数据,功能和预期输出。 (我知道在熊猫中使用其他方法可以轻松处理此示例,但我只想谈论groupby方法。谢谢)
series(a1, a2, a3, a4, a5...), (b1, b2, b3, b4, b5...)
答案 0 :(得分:0)
您可以解决以下问题:
# result is a Series of numpy arrays
result = (
pd.DataFrame({'A': A, 'B': B})
.groupby(level=0)
.apply(lambda x: f(x['A'], x['B'])))
# now result is a Series of float values
result = pd.Series(list(itertools.chain(*result.values)))