我需要找到存在率/流行的话在csv文件中由逗号分隔,为旁边的某个关键字的话行。
import pandas as pd
from elasticsearch import Elasticsearch
es = Elasticsearch("http://localhost:9200")
searchDB = pd.read_csv('')
searchDB = searchDB["AllKeywords"].str.split(', ')
searchDB = searchDB.explode()
df = pd.read_csv('') // keywords to look for
for i in range(len(df)):
keywordToSearch = df.loc[i, "H"]
res = es.search(index=searchDB["AllKeywords"], body={"from":0, "size":0, "query":{"match":{"sentence": df.loc[i, "H"]}}})
我在使用Elasticsearch的最后几行遇到错误。你能帮我吗?
Traceback (most recent call last):
File "/Users//PycharmProjects/DataImp/venv/lib/python3.9/site-packages/pandas/core/indexes/base.py", line 3629, in get_loc
return self._engine.get_loc(casted_key)
File "pandas/_libs/index.pyx", line 136, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/index.pyx", line 144, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/index_class_helper.pxi", line 41, in pandas._libs.index.Int64Engine._check_type
KeyError: 'AllKeywords'
1条答案
按热度按时间dldeef671#
您的错误似乎位于
index=searchDB["AllKeywords"]
清除变量