【发布时间】:2020-07-10 22:18:13
【问题描述】:
我有一个大数据框,它有两列但有很多行,所以这只是一个例子:
df1 = {"text":["see you in five minutes.", "she is my friend.", "she goes to school in five minutes.","he is my friend.","that is right.","sky is blue.","sky is yellow."],
"goal":[" "," "," "," "," "," "," "]}
我还有其他三个不同大小的数据框,但它们都有来自 df1 中文本列的一些行:
df2= {"text":["see you in five minutes.", "he is my friend."],
"second":["num","friend"]}
df3 = {"text":["she goes to school in five minutes.","she is my friend.","that is right."],
"third":["num","friend","correct"]}
df4 = {"text":["sky is blue.","sky is yellow."],
"fourth":["color","color"]}
我想要做的是将“第二”、“第三”和“第四”列合并到 df1,以便它们填充 df1 中的空列“目标”,
desired output:
df1 = {"text":["see you in five minutes.", "she is my friend.", "she goes to school in five minutes.","he is my friend.","that is right.","sky is blue.","sky is yellow."],
"goal":["num","friend","num","friend","correct","color","color"]}
我为每个数据框尝试了多次左合并,但输出将出现在不同的列中。有没有办法一次完成并将它们添加到目标列?
谢谢
【问题讨论】:
标签: python pandas dataframe merge