Pandas 比较对象列

Pandas compare Object columns

我有两个对象列,其中包含我根据 2 个 CSV 文件在熊猫上创建的数字列表。 我想比较其中两个并添加一个新列,该列将给出相同数字的数量。

例如: Table 1: Numbers to compare

Table 2: Data numbers according to date

我真正感兴趣的是 Table 2 中每个日期 Table 1 的任何数字的实际比较。

The desired result, adding a column, which indicates how many numbers exist in the table of the given number

非常感谢

表 1:

df1 = pd.DataFrame({
    'a':1, 'b':2, 'c':3, 'd':4
}, index=range(1))

表 2:

df2 = pd.DataFrame({
    'a':[1, 2, 2, 2], 
    'b':[2, 4, 3, 1],
    'c':[3, 5, 6, 3], 
    'd':[4, 7, 7, 5],
}, index=['01/01/2021', '02/01/2021', '03/02/2021', '04/02/2021'])

期望的结果:

df2['no of numbers'] = [
    list(row.isin(df1.values[0])).count(True) \
    for index, row in df2.iterrows()
]

应该可以。