espandas.py 文件源码

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

项目:espandas 作者: dashaub 项目源码 文件源码
def es_read(self, keys, index, doc_type):
        """
        Read from an ElasticSearch index and return a DataFrame
        :param keys: a list of keys to extract in elasticsearch
        :param index: the ElasticSearch index to read
        :param doc_type: the ElasticSearch doc_type to read
        """
        self.successful_ = 0
        self.failed_ = 0

        # Collect records for all of the keys
        records = []
        for key in keys:
            try:
                record = self.client.get(index=index, doc_type=doc_type, id=key)
                self.successful_ += 1
                if '_source' in record:
                    records.append(record['_source'])
            except NotFoundError as nfe:
                print('Key not found: %s' % nfe)
                self.failed_ += 1

        # Prepare the records into a single DataFrame
        df = None
        if records:
            df = pd.DataFrame(records).fillna(value=np.nan)
            df = df.reindex_axis(sorted(df.columns), axis=1)
        return df
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号