将数据转储到Pandasd

2024-05-16 01:33:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从elastic search获得超过10000条观测数据,并将其放入熊猫数据中框架:-在

es_index = "logstash-2018.08.26"
documento = "your_doc_type"


body = {"from": 0, "size": 100,
    "query": {
        "constant_score" : {
            "filter" : {
                 "bool" : {
                    "must" : [{
              "range": {"@timestamp" : {
                "gte": "2018-08-26T14:00:08.000Z", 
                "lte": "2018-08-26T16:00:00.000Z"

            }}
          }],
                   "filter": [
                        {"term"  :{"type" :"vx_apache_json"}},
                        {"term"  :{"api" :"viv_signin.php"}},
                        {"term"  :{"domain":"fnwp"}}




                   ]
                 }}}}}

res = helpers.scan(
                client = es,
                scroll = '2s',
                query = body, 
                index = es_index)

当我试图得到资源的价值时

^{pr2}$

当我使用下面的代码。。在

for i in res:
 print(i)

我正在获取以下格式的数据

enter image description here

我想把这个转换成一个pandas的数据框下图:- enter image description here


Tags: 数据框架searchyourindexestypebody
2条回答

我可以给你一个更好的办法。。我猜你想弄到一万多张唱片。。试试下面的方法,你也会得到数百万张唱片:——

首次安装

from elasticsearch_dsl import Search

1.)定义客户

^{pr2}$

2.)search = Search(using=client)

3.)检查点击总数

results = search.execute()
results.hits.total

4.)s = Search(using=client)

5)写下你的疑问

s = s.query(..write your query here...)

6.)使用扫描将数据转储到数据帧中…扫描会将所有数据转储到数据帧中,即使数据以十亿计,因此请小心。在

results_df = pd.DataFrame((d.to_dict() for d in s.scan()))

7.)看看你的数据框,然后微笑:)

results_df

将所有数据存储在一个变量中,然后使用pd数据帧(你的变量)。在

相关问题 更多 >