删除数据框中两列重复的对象

Remove objects which has been repeated in two columns in dataframe

我有一个这样的数据框:

CSV文件中的数据集为here.

此数据是从 IMDb 数据集中提取的。 但我有一个问题,我无法删除在同一行中重复的演员姓名,例如在第 4 行中我想在名称和演员列中删除 'Marie Gruber'。 我尝试使用 to apply 和 all conditions 但代码总是认为它是相同的。 喜欢这个代码:

data[data['name'] != data['actors']]

使用pandas.dataframe.drop函数。

data.drop(data[data.apply(lambda x: x['name'] in x['actors'], axis = 1)].index)

actors 列有尾随空格,首先按 Series.str.strip:

删除它们
data['actors'] = data['actors'].str.strip()
data[data['name'] != data['actors']]

或在read_csv中使用skipinitialspace=True:

data = pd.read_csv(file, skipinitialspace=True)
data[data['name'] != data['actors']]