Python 3.x 将数据框文本与字典匹配:加快过程
我试图将pandas数据帧单元格中的列表与dictionaryPython 3.x 将数据框文本与字典匹配:加快过程,python-3.x,pandas,dictionary,Python 3.x,Pandas,Dictionary,我试图将pandas数据帧单元格中的列表与dictionarymesh中的标记进行比较,并在另一列中的列表中生成命中率。 例如,dict如下所示: { "mesh-tag 1": ( [list of UIs], [list of treenumbers] ), "mesh-tag 2": ( [list of UIs ], [list of treenumbers] ), ...} 我的目标是将抽象文本AbsText与字典
mesh
中的标记进行比较,并在另一列中的列表中生成命中率。
例如,dict如下所示:
{ "mesh-tag 1": (
[list of UIs],
[list of treenumbers]
),
"mesh-tag 2": (
[list of UIs ],
[list of treenumbers]
), ...}
我的目标是将抽象文本AbsText
与字典中的mesh标记进行比较,并在另一列中生成每个抽象的命中列表。因此,我使用嵌套循环:
for i in abstractdf.index:
# line for line
meshlist = []
UIlist = []
for meshterm in mesh.keys():
# tag for tag
if meshterm in abstractdf["AbsText"][i]:
meshlist.append(meshterm)
UIlist.append(mesh[meshterm][0])
abstractdf.set_value(i, "MeSH-Term", meshlist)
abstractdf.set_value(i, "Descriptor-UI", UIlist)
这实际上是可行的,但即使是一个很小的测试数据帧也需要很长时间。由于我是一名新的编码员,我知道这可能是间接的…:(
是否有任何可能性,例如使用np.where
函数或其他方法来加快进程
任何帮助或建议都会很好