当前位置: 首页>>代码示例>>Python>>正文


Python common.sentinel_factory方法代码示例

本文整理汇总了Python中pandas.core.common.sentinel_factory方法的典型用法代码示例。如果您正苦于以下问题:Python common.sentinel_factory方法的具体用法?Python common.sentinel_factory怎么用?Python common.sentinel_factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandas.core.common的用法示例。


在下文中一共展示了common.sentinel_factory方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_level_lengths

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import sentinel_factory [as 别名]
def _get_level_lengths(index):
    """
    Given an index, find the level lenght for each element.

    Result is a dictionary of (level, inital_position): span
    """
    sentinel = sentinel_factory()
    levels = index.format(sparsify=sentinel, adjoin=False, names=False)

    if index.nlevels == 1:
        return {(0, i): 1 for i, value in enumerate(levels)}

    lengths = {}

    for i, lvl in enumerate(levels):
        for j, row in enumerate(lvl):
            if not get_option('display.multi_sparse'):
                lengths[(i, j)] = 1
            elif row != sentinel:
                last_label = j
                lengths[(i, last_label)] = 1
            else:
                lengths[(i, last_label)] += 1

    return lengths 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:27,代码来源:style.py

示例2: _get_level_lengths

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import sentinel_factory [as 别名]
def _get_level_lengths(index, hidden_elements=None):
    """
    Given an index, find the level length for each element.

    Optional argument is a list of index positions which
    should not be visible.

    Result is a dictionary of (level, inital_position): span
    """
    sentinel = com.sentinel_factory()
    levels = index.format(sparsify=sentinel, adjoin=False, names=False)

    if hidden_elements is None:
        hidden_elements = []

    lengths = {}
    if index.nlevels == 1:
        for i, value in enumerate(levels):
            if(i not in hidden_elements):
                lengths[(0, i)] = 1
        return lengths

    for i, lvl in enumerate(levels):
        for j, row in enumerate(lvl):
            if not get_option('display.multi_sparse'):
                lengths[(i, j)] = 1
            elif (row != sentinel) and (j not in hidden_elements):
                last_label = j
                lengths[(i, last_label)] = 1
            elif (row != sentinel):
                # even if its hidden, keep track of it in case
                # length >1 and later elements are visible
                last_label = j
                lengths[(i, last_label)] = 0
            elif(j not in hidden_elements):
                lengths[(i, last_label)] += 1

    non_zero_lengths = {
        element: length for element, length in lengths.items() if length >= 1}

    return non_zero_lengths 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:43,代码来源:style.py

示例3: _get_level_lengths

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import sentinel_factory [as 别名]
def _get_level_lengths(index, hidden_elements=None):
    """
    Given an index, find the level length for each element.
    Optional argument is a list of index positions which
    should not be visible.

    Result is a dictionary of (level, inital_position): span
    """
    sentinel = com.sentinel_factory()
    levels = index.format(sparsify=sentinel, adjoin=False, names=False)

    if hidden_elements is None:
        hidden_elements = []

    lengths = {}
    if index.nlevels == 1:
        for i, value in enumerate(levels):
            if(i not in hidden_elements):
                lengths[(0, i)] = 1
        return lengths

    for i, lvl in enumerate(levels):
        for j, row in enumerate(lvl):
            if not get_option('display.multi_sparse'):
                lengths[(i, j)] = 1
            elif (row != sentinel) and (j not in hidden_elements):
                last_label = j
                lengths[(i, last_label)] = 1
            elif (row != sentinel):
                # even if its hidden, keep track of it in case
                # length >1 and later elements are visible
                last_label = j
                lengths[(i, last_label)] = 0
            elif(j not in hidden_elements):
                lengths[(i, last_label)] += 1

    non_zero_lengths = {}
    for element, length in lengths.items():
        if(length >= 1):
            non_zero_lengths[element] = length

    return non_zero_lengths 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:44,代码来源:style.py

示例4: _write_hierarchical_rows

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import sentinel_factory [as 别名]
def _write_hierarchical_rows(self, fmt_values, indent):
        template = 'rowspan="%d" valign="top"'

        frame = self.frame
        ncols = min(len(self.columns), self.max_cols)
        nrows = min(len(self.frame), self.max_rows)

        truncate = (len(frame) > self.max_rows)

        idx_values = frame.index[:nrows].format(sparsify=False, adjoin=False,
                                                names=False)
        idx_values = lzip(*idx_values)

        if self.fmt.sparsify:

            # GH3547
            sentinel = com.sentinel_factory()
            levels = frame.index[:nrows].format(sparsify=sentinel,
                                                adjoin=False, names=False)
            # Truncate row names
            if truncate:
                levels = [lev[:self.max_rows] for lev in levels]

            level_lengths = _get_level_lengths(levels, sentinel)

            for i in range(min(len(frame), self.max_rows)):
                row = []
                tags = {}

                sparse_offset = 0
                j = 0
                for records, v in zip(level_lengths, idx_values[i]):
                    if i in records:
                        if records[i] > 1:
                            tags[j] = template % records[i]
                    else:
                        sparse_offset += 1
                        continue

                    j += 1
                    row.append(v)

                row.extend(fmt_values[j][i] for j in range(ncols))
                self.write_tr(row, indent, self.indent_delta, tags=tags,
                              nindex_levels=len(levels) - sparse_offset)
        else:
            for i in range(len(frame)):
                idx_values = list(zip(*frame.index.format(sparsify=False,
                                                          adjoin=False,
                                                          names=False)))
                row = []
                row.extend(idx_values[i])
                row.extend(fmt_values[j][i] for j in range(ncols))
                self.write_tr(row, indent, self.indent_delta, tags=None,
                              nindex_levels=frame.index.nlevels)

        # Truncation markers (...)
        if truncate:
            row = ([''] * frame.index.nlevels) + (['...'] * ncols)
            self.write_tr(row, indent, self.indent_delta, tags=None) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:62,代码来源:format.py


注:本文中的pandas.core.common.sentinel_factory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。