本文整理汇总了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))
示例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
示例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
示例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))