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


Python compat.iterkeys方法代碼示例

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


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

示例1: test_missing_value_conversion

# 需要導入模塊: from pandas import compat [as 別名]
# 或者: from pandas.compat import iterkeys [as 別名]
def test_missing_value_conversion(self, file):
        columns = ['int8_', 'int16_', 'int32_', 'float32_', 'float64_']
        smv = StataMissingValue(101)
        keys = [key for key in iterkeys(smv.MISSING_VALUES)]
        keys.sort()
        data = []
        for i in range(27):
            row = [StataMissingValue(keys[i + (j * 27)]) for j in range(5)]
            data.append(row)
        expected = DataFrame(data, columns=columns)

        parsed = read_stata(getattr(self, file), convert_missing=True)
        tm.assert_frame_equal(parsed, expected) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:15,代碼來源:test_stata.py

示例2: _do_convert_categoricals

# 需要導入模塊: from pandas import compat [as 別名]
# 或者: from pandas.compat import iterkeys [as 別名]
def _do_convert_categoricals(self, data, value_label_dict, lbllist,
                                 order_categoricals):
        """
        Converts categorical columns to Categorical type.
        """
        value_labels = list(compat.iterkeys(value_label_dict))
        cat_converted_data = []
        for col, label in zip(data, lbllist):
            if label in value_labels:
                # Explicit call with ordered=True
                cat_data = Categorical(data[col], ordered=order_categoricals)
                categories = []
                for category in cat_data.categories:
                    if category in value_label_dict[label]:
                        categories.append(value_label_dict[label][category])
                    else:
                        categories.append(category)  # Partially labeled
                try:
                    cat_data.categories = categories
                except ValueError:
                    vc = Series(categories).value_counts()
                    repeats = list(vc.index[vc > 1])
                    repeats = '\n' + '-' * 80 + '\n'.join(repeats)
                    raise ValueError('Value labels for column {col} are not '
                                     'unique. The repeated labels are:\n'
                                     '{repeats}'
                                     .format(col=col, repeats=repeats))
                # TODO: is the next line needed above in the data(...) method?
                cat_data = Series(cat_data, index=data.index)
                cat_converted_data.append((col, cat_data))
            else:
                cat_converted_data.append((col, data[col]))
        data = DataFrame.from_dict(OrderedDict(cat_converted_data))
        return data 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:36,代碼來源:stata.py

示例3: _do_convert_categoricals

# 需要導入模塊: from pandas import compat [as 別名]
# 或者: from pandas.compat import iterkeys [as 別名]
def _do_convert_categoricals(self, data, value_label_dict, lbllist,
                                 order_categoricals):
        """
        Converts categorical columns to Categorical type.
        """
        value_labels = list(compat.iterkeys(value_label_dict))
        cat_converted_data = []
        for col, label in zip(data, lbllist):
            if label in value_labels:
                # Explicit call with ordered=True
                cat_data = Categorical(data[col], ordered=order_categoricals)
                categories = []
                for category in cat_data.categories:
                    if category in value_label_dict[label]:
                        categories.append(value_label_dict[label][category])
                    else:
                        categories.append(category)  # Partially labeled
                try:
                    cat_data.categories = categories
                except ValueError:
                    vc = Series(categories).value_counts()
                    repeats = list(vc.index[vc > 1])
                    repeats = '\n' + '-' * 80 + '\n'.join(repeats)
                    msg = 'Value labels for column {0} are not unique. The ' \
                          'repeated labels are:\n{1}'.format(col, repeats)
                    raise ValueError(msg)
                # TODO: is the next line needed above in the data(...) method?
                cat_data = Series(cat_data, index=data.index)
                cat_converted_data.append((col, cat_data))
            else:
                cat_converted_data.append((col, data[col]))
        data = DataFrame.from_dict(OrderedDict(cat_converted_data))
        return data 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:35,代碼來源:stata.py

示例4: to_pickle

# 需要導入模塊: from pandas import compat [as 別名]
# 或者: from pandas.compat import iterkeys [as 別名]
def to_pickle(dates, path):
        rules = []
        keys = sorted(compat.iterkeys(dates))
        for dt in keys:
            name = dates[dt]
            h = holiday.Holiday(
                name, dt.year, month=dt.month, day=dt.day)
            rules.append(h)

        with open(path, mode='wb') as w:
            compat.cPickle.dump(rules, w, protocol=2)
            print('pickled {0} data'.format(len(dates))) 
開發者ID:sinhrks,項目名稱:japandas,代碼行數:14,代碼來源:holiday.py

示例5: _do_convert_categoricals

# 需要導入模塊: from pandas import compat [as 別名]
# 或者: from pandas.compat import iterkeys [as 別名]
def _do_convert_categoricals(self, data, value_label_dict, lbllist,
                                 order_categoricals):
        """
        Converts categorical columns to Categorical type.
        """
        value_labels = list(compat.iterkeys(value_label_dict))
        cat_converted_data = []
        for col, label in zip(data, lbllist):
            if label in value_labels:
                # Explicit call with ordered=True
                cat_data = Categorical(data[col], ordered=order_categoricals)
                categories = []
                for category in cat_data.categories:
                    if category in value_label_dict[label]:
                        categories.append(value_label_dict[label][category])
                    else:
                        categories.append(category)  # Partially labeled
                try:
                    cat_data.categories = categories
                except ValueError:
                    vc = Series(categories).value_counts()
                    repeats = list(vc.index[vc > 1])
                    repeats = '\n' + '-' * 80 + '\n'.join(repeats)
                    msg = 'Value labels for column {0} are not unique. The ' \
                          'repeated labels are:\n{1}'.format(col, repeats)
                    raise ValueError(msg)
                # TODO: is the next line needed above in the data(...) method?
                cat_data = Series(cat_data, index=data.index)
                cat_converted_data.append((col, cat_data))
            else:
                cat_converted_data.append((col, data[col]))
        data = DataFrame.from_items(cat_converted_data)
        return data 
開發者ID:nccgroup,項目名稱:Splunking-Crime,代碼行數:35,代碼來源:stata.py


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