【发布时间】:2017-06-22 22:39:02
【问题描述】:
我有两个不同形状的 df。一个包含单词及其频率,另一个包含单词及其lemmas。
第一个 df 总是将一个词映射到一个频率, 第二个 df 将许多单词映射到一个引理(多次)。例如:
df1:
word frequency
de 33504559
que 32700217
no 28263302
a 21978600
la 21249418
和df2:
lemma word
zurullo zurullos
zurupeto zurupetos
zutano zutana
zutano zutanas
zutano zutanos
我想将引理信息添加到df1,通过搜索df1 中的每个单词,将其与df2 中的单词进行比较,然后从df2 中提取引理信息以将其添加回@ 987654329@.
when the value is always the same in df1 有一些有用的答案,但由于我想对包含不同单词的每一行执行此操作,所以我不确定如何继续。 (我检查了the merging and concatenating docs section,但重新浮出水面时比以前更加困惑......)
在 just-python 中我会使用循环,例如:
new_df = dict()
# assuming all dfs are dicts
for w, f in df1.items():
if w in df2.keys():
new_df[w] = (df2[w], f)
很高兴使用 pandas 数据帧操作了解更多有关此内容的信息。
【问题讨论】: