本文整理汇总了Python中etl.ETLUtils.keep_fields方法的典型用法代码示例。如果您正苦于以下问题:Python ETLUtils.keep_fields方法的具体用法?Python ETLUtils.keep_fields怎么用?Python ETLUtils.keep_fields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类etl.ETLUtils
的用法示例。
在下文中一共展示了ETLUtils.keep_fields方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prepare
# 需要导入模块: from etl import ETLUtils [as 别名]
# 或者: from etl.ETLUtils import keep_fields [as 别名]
def prepare(self):
print('prepare: %s' % time.strftime("%Y/%m/%d-%H:%M:%S"))
self.headers = build_headers(len(self.sense_groups))
if Constants.USE_CONTEXT is True:
for record in self.train_records:
record.update(record[Constants.CONTEXT_WORDS_FIELD])
for record in self.records_to_predict:
record.update(record[Constants.CONTEXT_WORDS_FIELD])
if Constants.FM_REVIEW_TYPE:
self.train_records = ETLUtils.filter_records(
self.train_records, Constants.PREDICTED_CLASS_FIELD,
[Constants.FM_REVIEW_TYPE])
# ETLUtils.drop_fields([Constants.TOPICS_FIELD], self.train_records)
ETLUtils.keep_fields(self.headers, self.train_records)
ETLUtils.keep_fields(self.headers, self.records_to_predict)
ETLUtils.save_csv_file(
self.csv_train_file, self.train_records, self.headers)
ETLUtils.save_csv_file(
self.csv_test_file, self.records_to_predict, self.headers)
print('Exported CSV and JSON files: %s'
% time.strftime("%Y/%m/%d-%H:%M:%S"))
csv_files = [
self.csv_train_file,
self.csv_test_file
]
print('num_cols', len(self.headers))
libfm_converter.csv_to_libfm(
csv_files, 0, [1, 2], [], ',', has_header=True,
suffix='.libfm')
print('Exported LibFM files: %s' % time.strftime("%Y/%m/%d-%H:%M:%S"))