Skip to main content
added 79 characters in body
Source Link
Jaroslav Bezděk
  • 7.7k
  • 6
  • 34
  • 59

You can achieve this by set.intersection_update()pandas.DataFrame.apply() and set.intersection(), like this:

outputcols_set = setlist(df[df.columns[0]]df.uniqueapply()) forlambda col in: dfset(col.columns[1:]:values)).values)  output = output.intersection_updatelist(set(df[col].uniqueintersection()*cols_set)) 

The result is following:

>>> print(list(output)) ['tim', 'bob'] 

You can achieve this by set.intersection_update(), like this:

output = set(df[df.columns[0]].unique()) for col in df.columns[1:]:   output.intersection_update(set(df[col].unique())) 

The result is following:

>>> print(list(output)) ['tim', 'bob'] 

You can achieve this by pandas.DataFrame.apply() and set.intersection(), like this:

cols_set = list(df.apply(lambda col: set(col.values)).values) output = list(set.intersection(*cols_set)) 

The result is following:

>>> print(output) ['tim', 'bob'] 
Post Undeleted by Jaroslav Bezděk
Post Deleted by Jaroslav Bezděk
Source Link
Jaroslav Bezděk
  • 7.7k
  • 6
  • 34
  • 59

You can achieve this by set.intersection_update(), like this:

output = set(df[df.columns[0]].unique()) for col in df.columns[1:]: output.intersection_update(set(df[col].unique())) 

The result is following:

>>> print(list(output)) ['tim', 'bob']