當前位置: 首頁>>代碼示例>>Python>>正文


Python lib.generate_slices方法代碼示例

本文整理匯總了Python中pandas._libs.lib.generate_slices方法的典型用法代碼示例。如果您正苦於以下問題:Python lib.generate_slices方法的具體用法?Python lib.generate_slices怎麽用?Python lib.generate_slices使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pandas._libs.lib的用法示例。


在下文中一共展示了lib.generate_slices方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __iter__

# 需要導入模塊: from pandas._libs import lib [as 別名]
# 或者: from pandas._libs.lib import generate_slices [as 別名]
def __iter__(self):
        sdata = self._get_sorted_data()

        if self.ngroups == 0:
            # we are inside a generator, rather than raise StopIteration
            # we merely return signal the end
            return

        starts, ends = lib.generate_slices(self.slabels, self.ngroups)

        for i, (start, end) in enumerate(zip(starts, ends)):
            # Since I'm now compressing the group ids, it's now not "possible"
            # to produce empty slices because such groups would not be observed
            # in the data
            # if start >= end:
            #     raise AssertionError('Start %s must be less than end %s'
            #                          % (str(start), str(end)))
            yield i, self._chop(sdata, slice(start, end)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:20,代碼來源:ops.py

示例2: fast_apply

# 需要導入模塊: from pandas._libs import lib [as 別名]
# 或者: from pandas._libs.lib import generate_slices [as 別名]
def fast_apply(self, f, names):
        # must return keys::list, values::list, mutated::bool
        try:
            starts, ends = lib.generate_slices(self.slabels, self.ngroups)
        except Exception:
            # fails when all -1
            return [], True

        sdata = self._get_sorted_data()
        results, mutated = reduction.apply_frame_axis0(sdata, f, names,
                                                       starts, ends)

        return results, mutated 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:15,代碼來源:ops.py

示例3: fast_apply

# 需要導入模塊: from pandas._libs import lib [as 別名]
# 或者: from pandas._libs.lib import generate_slices [as 別名]
def fast_apply(self, f, names):
        # must return keys::list, values::list, mutated::bool
        try:
            starts, ends = lib.generate_slices(self.slabels, self.ngroups)
        except:
            # fails when all -1
            return [], True

        sdata = self._get_sorted_data()
        results, mutated = lib.apply_frame_axis0(sdata, f, names, starts, ends)

        return results, mutated 
開發者ID:nccgroup,項目名稱:Splunking-Crime,代碼行數:14,代碼來源:groupby.py

示例4: _fast_split_df

# 需要導入模塊: from pandas._libs import lib [as 別名]
# 或者: from pandas._libs.lib import generate_slices [as 別名]
def _fast_split_df(g_df):
    """
    Note
    ----

    splitting does not scale well to many groups (e.g. 50000+). This is due
    to pandas' (1) use of indexes, (2) some hard coded actions when subsetting.
    We are currently working on a fix, so that when people aren't using indexes,
    nesting will be much faster.

    see https://github.com/machow/siuba/issues/184
    """

    # TODO (#184): speed up when user doesn't need an index
    # right now, this is essentially a copy of
    # pandas.core.groupby.ops.DataSplitter.__iter__
    from pandas._libs import lib
    splitter = g_df.grouper._get_splitter(g_df.obj)

    starts, ends = lib.generate_slices(splitter.slabels, splitter.ngroups)

    # TODO: reset index
    sdata = splitter._get_sorted_data()

    # TODO: avoid costly make_block call, and hard-coded BlockManager init actions.
    #       neither of these things is necessary when subsetting rows.
    for start, end in zip(starts, ends):
        yield splitter._chop(sdata, slice(start, end)) 
開發者ID:machow,項目名稱:siuba,代碼行數:30,代碼來源:verbs.py


注:本文中的pandas._libs.lib.generate_slices方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。