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


Python ETLUtils.filter_out_records方法代码示例

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


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

示例1: update_labeled_reviews_records

# 需要导入模块: from etl import ETLUtils [as 别名]
# 或者: from etl.ETLUtils import filter_out_records [as 别名]
def update_labeled_reviews_records():

    reviews_label_map = compare_records()
    agreed_review_ids = set(reviews_label_map.keys())
    classifier_records = \
        ETLUtils.load_json_file(Constants.CLASSIFIED_RECORDS_FILE)
    classifier_review_ids = \
        {record[Constants.REVIEW_ID_FIELD] for record in classifier_records}
    non_agreed_review_ids = classifier_review_ids.difference(agreed_review_ids)

    # for record in classifier_records:
        # print(record)

    print('number of records before: %d' % len(classifier_records))

    print(reviews_label_map)
    print(non_agreed_review_ids)
    review_type_map = {'s': 'yes', 'g': 'no'}

    # We remove from the classifier records the ones who don't have agreed on a
    # label
    classifier_records = ETLUtils.filter_out_records(
        classifier_records, Constants.REVIEW_ID_FIELD, non_agreed_review_ids)

    # Finally we make the update of the labels
    for record in classifier_records:
        review_id = record[Constants.REVIEW_ID_FIELD]
        record[Constants.SPECIFIC] = review_type_map[reviews_label_map[review_id]]
        # print(record)

    print('number of records after: %d' % len(classifier_records))
开发者ID:melqkiades,项目名称:yelp,代码行数:33,代码来源:labeled_reviews_comparator.py

示例2: foo

# 需要导入模块: from etl import ETLUtils [as 别名]
# 或者: from etl.ETLUtils import filter_out_records [as 别名]
def foo():
    my_records = []
    for i in range(10):
        my_records.append({'column1': i})
    print(my_records)
    to_remove = set(range(1, 10, 2))
    print(to_remove)

    new_records = ETLUtils.filter_out_records(my_records, 'column1', to_remove)
    print(new_records)
开发者ID:melqkiades,项目名称:yelp,代码行数:12,代码来源:labeled_reviews_comparator.py

示例3: test_filter_out_records

# 需要导入模块: from etl import ETLUtils [as 别名]
# 或者: from etl.ETLUtils import filter_out_records [as 别名]
    def test_filter_out_records(self):

        field = 'offering_id'
        values = [1, 3, 5]

        expected_result = [
            {'user_id': 'U1', 'offering_id': 2, 'overall_rating': 7.0},
            {'user_id': 'U1', 'offering_id': 4, 'overall_rating': 7.0},
            {'user_id': 'U2', 'offering_id': 2, 'overall_rating': 7.0},
            {'user_id': 'U2', 'offering_id': 4, 'overall_rating': 7.0}
        ]

        actual_result = ETLUtils.filter_out_records(reviews_matrix_5_short, field, values)

        self.assertEqual(expected_result, actual_result)
开发者ID:antoine-tran,项目名称:yelp,代码行数:17,代码来源:test_etl_utils.py


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