0

我想遍历数据框中的组。这在熊猫中是可能的,但是当我将它移植到考拉时,我得到一个错误。

import databricks.koalas as ks
import pandas as pd

pdf = pd.DataFrame({'x':range(3), 'y':['a','b','b'], 'z':['a','b','b']})

# Create a Koalas DataFrame from pandas DataFrame
df = ks.from_pandas(pdf)

for a in df.groupby('x'):
    print(a)

这是错误:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-35-d4164d1f71e0> in <module>
----> 1 for a in df.groupby('x'):
      2     print(a)

/opt/conda/lib/python3.7/site-packages/databricks/koalas/groupby.py in __getitem__(self, item)
   2630         if self._as_index and is_name_like_value(item):
   2631             return SeriesGroupBy(
-> 2632                 self._kdf._kser_for(item if is_name_like_tuple(item) else (item,)),
   2633                 self._groupkeys,
   2634                 dropna=self._dropna,

/opt/conda/lib/python3.7/site-packages/databricks/koalas/frame.py in _kser_for(self, label)
    721         Name: id, dtype: int64
    722         """
--> 723         return self._ksers[label]
    724 
    725     def _apply_series_op(self, op, should_resolve: bool = False):

KeyError: (0,)

这种群体迭代在考拉中是否可行?考拉文档有点暗示这是可能的 - https://koalas.readthedocs.io/en/latest/reference/groupby.html

4

1 回答 1

0

Groupby 迭代尚未实现:

https://github.com/databricks/koalas/issues/2014

于 2021-01-21T17:44:46.170 回答