top of page
import pandas as pd
data = [[1, 1, 0], [1, 1, 1], [1, 1, 2], [1, 2, 3], [1, 2, 4], [2, 1, 5], [2, 1, 6]]
actor_director = pd.DataFrame(data, columns=['actor_id', 'director_id', 'timestamp']).astype({'actor_id':'int64', 'director_id':'int64', 'timestamp':'int64'})
def actors_and_directors(actor_director: pd.DataFrame) -> pd.DataFrame:
grouped = actor_director.groupby(['actor_id', 'director_id']).size().reset_index(name='cooperation_count')
filtered_pairs = grouped[grouped['cooperation_count'] >= 3]
return filtered_pairs[['actor_id', 'director_id']]
result = actors_and_directors(actor_director)
print(result)
bottom of page