【发布时间】:2017-02-13 18:09:19
【问题描述】:
给定两个 pandas 数据框:
df1 = pd.read_csv(file1, names=['col1','col2','col3'])
df2 = pd.read_csv(file2, names=['col1','col2','col3'])
我想删除 df2 中 col1 或 col2(或两者)的值在 df1 中不存在的所有行。
执行以下操作:
df2 = df2[(df2['col1'] in set(df1['col1'])) & (df2['col2'] in set(df1['col2']))]
产量:
TypeError: 'Series' 对象是可变的,因此它们不能被散列
【问题讨论】:
标签: python pandas indexing merge multiple-columns