【发布时间】:2021-09-02 02:01:59
【问题描述】:
我有两个不同的数据框,在第一个中我有唯一的 id,在第二个中我有与唯一的相同的 id,它们可能会出现多次,有些可能不会出现。
我想计算每个 id 在数据框 2 中重复的次数,然后与数据框 1 合并到相应的 id 中。
数据框 1:
id_unique name
400 t1
450 t2
300 t10
600 t20
650 t30
数据框 2:
id other_columns
400 s1
400 s2
650 s3
600 s4
600 s5
600 s6
想要的结果:
id_unique name count_df2
400 t1 2
450 t2 0
300 t10 0
600 t20 3
650 t30 1
我该怎么做?
【问题讨论】:
标签: python pandas dataframe group-by merge