我有两个pandas Dataframe (2020年上半年和2020年下半年)与客户,以及他们购买的产品。有没有一种有效的方法来找出哪些顾客在第二部分买了什么,哪些顾客在第一部分没有买?
H1_2020:
| 产品展示| Product |
| --| ------------ |
| A| A |
| B| B |
| A| A |
| A| A |
h2_2020:
| 产品展示| Product |
| --| ------------ |
| A| A |
| B| B |
| C| C |
| A| A |
因此,基于上述两个表的输出应为:
| 买了一个新的东西在半年2?||
| --| ------------ |
| 0| 0 |
| 1| 1 |
| 1| 1 |
5条答案
按热度按时间hl0ma9xz1#
使用
pd.merge
。如果您在h2_2020中有新客户,他们将出现在最终输出中:a64a0gku2#
您可以使用设置的差异来比较这些值
wmomyfyw3#
加入并检查哪个记录仅来自
h2_2020
:r55awzrz4#
如果两个数据集的客户集相同,则可以执行以下操作:
4ngedf3f5#
我更改了dataframe h2_2020,添加了客户4,以防新客户进入
所以我结果有其他列指示客户是否是半2中的新客户。