field_values.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:skills-ml 作者: workforce-data-initiative 项目源码 文件源码
def save(self, s3_conn, s3_prefix):
        """Save stats to S3, including percentages
        Args:
            s3_conn (boto.Connection) - an s3 connection
            s3_prefix (str) s3 path (including bucket) to save dataset stats
        """
        bucket_name, prefix = split_s3_path(s3_prefix)
        bucket = s3_conn.get_bucket(bucket_name)
        for field_name, counts in self.accumulator.items():
            output = BytesIO()
            writer = csv.writer(output)
            for value, count in counts.most_common():
                writer.writerow([value, count])

            key = boto.s3.key.Key(
                bucket=bucket,
                name='{}/{}/{}/{}.csv'.format(
                    prefix,
                    self.directory,
                    self.quarter,
                    field_name
                )
            )
            logging.info('Writing stats to %s', key)
            output.seek(0)
            key.set_contents_from_string(output.getvalue())
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号