From 597ef55d896c946b0e049c0b881bb5771932586f Mon Sep 17 00:00:00 2001 From: Sangeeth Santhosh <73825180+sangeeths29@users.noreply.github.com> Date: Sat, 21 Jun 2025 23:24:02 -0700 Subject: [PATCH] Add files via upload --- 01-GroupSoldProductsByTheDate.py | 10 ++++++++++ 02-DailyLeadsandPartners.py | 10 ++++++++++ 03-ActorsandDirectorswhoCooperatedAtLeastThreeTimes.py | 7 +++++++ 3 files changed, 27 insertions(+) create mode 100644 01-GroupSoldProductsByTheDate.py create mode 100644 02-DailyLeadsandPartners.py create mode 100644 03-ActorsandDirectorswhoCooperatedAtLeastThreeTimes.py diff --git a/01-GroupSoldProductsByTheDate.py b/01-GroupSoldProductsByTheDate.py new file mode 100644 index 0000000..3103532 --- /dev/null +++ b/01-GroupSoldProductsByTheDate.py @@ -0,0 +1,10 @@ +# Problem 1 - Group Sold Products by the Date (https://leetcode.com/problems/group-sold-products-by-the-date/) +import pandas as pd + +def categorize_products(activities: pd.DataFrame) -> pd.DataFrame: + groups = activities.groupby('sell_date').agg( + num_sold = ('product', 'nunique'), + product = ('product', lambda x : ','.join(sorted(set(x)))) + ).reset_index() + + return groups.sort_values(by = ['sell_date']).rename(columns = {'product' : 'products'}) \ No newline at end of file diff --git a/02-DailyLeadsandPartners.py b/02-DailyLeadsandPartners.py new file mode 100644 index 0000000..d1cd60f --- /dev/null +++ b/02-DailyLeadsandPartners.py @@ -0,0 +1,10 @@ +# Problem 2 - Daily Leads and Partners ( https://leetcode.com/problems/daily-leads-and-partners/ ) +import pandas as pd + +def daily_leads_and_partners(daily_sales: pd.DataFrame) -> pd.DataFrame: + salegroups = daily_sales.groupby(['date_id', 'make_name']).agg( + unique_leads = ('lead_id', 'nunique'), + unique_partners = ('partner_id', 'nunique') + ).reset_index() + + return salegroups.sort_values(by = ['date_id']) \ No newline at end of file diff --git a/03-ActorsandDirectorswhoCooperatedAtLeastThreeTimes.py b/03-ActorsandDirectorswhoCooperatedAtLeastThreeTimes.py new file mode 100644 index 0000000..eb239e2 --- /dev/null +++ b/03-ActorsandDirectorswhoCooperatedAtLeastThreeTimes.py @@ -0,0 +1,7 @@ +# Problem 3 - Actors and Directors who Cooperated At Least Three Times (https://leetcode.com/problems/actors-and-directors-who-cooperated-at-least-three-times/) +import pandas as pd + +def actors_and_directors(actor_director: pd.DataFrame) -> pd.DataFrame: + counts = actor_director.groupby(['actor_id', 'director_id']).size().reset_index(name='count') + freq_pairs = counts[counts['count'] >= 3] + return freq_pairs[['actor_id', 'director_id']] \ No newline at end of file