【发布时间】:2019-02-16 01:15:45
【问题描述】:
*我是 Python 和 Pandas 的新手
我需要执行以下操作
我有 2 个 DataFrame,我们称它们为 df1 和 df2
df1
Index Req ID City_Atlanta City_Seattle City_Boston Result
0 X 1 0 0 0
1 Y 0 1 0 0
2 Z 0 0 1 1
df2
Index Req_ID City
0 X Atlanta
1 Y Seattle
2 Z Boston
我想在 df2 中添加一个名为 result 的列,如果 df1.result = 0 则 df2.result = False,如果 df1.result = 1 则 df2.result = True
最终结果应该是这样的 df2
Index Req_ID City result
0 X Atlanta False
1 Y Seattle False
2 Z Boston True
我对 Stack Overflow 也很陌生,所以请原谅任何常见的错误。
【问题讨论】:
-
基于什么? 2个数据帧之间的共同键是什么?你能解释一下吗?
-
索引或 Req_ID