From a72d832c22cf78f293f4a887e5723d520dbb676a Mon Sep 17 00:00:00 2001 From: Paneri Patel Date: Thu, 19 Jun 2025 02:27:15 -0400 Subject: [PATCH] Done Pandas10 --- ActorsAndDirectorsWhoCooperatedAtLeastThreeTimes.py | 10 ++++++++++ DailyLeadsAndPartners.py | 12 ++++++++++++ GroupSoldProductsByTheDate.py | 13 +++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 ActorsAndDirectorsWhoCooperatedAtLeastThreeTimes.py create mode 100644 DailyLeadsAndPartners.py create mode 100644 GroupSoldProductsByTheDate.py diff --git a/ActorsAndDirectorsWhoCooperatedAtLeastThreeTimes.py b/ActorsAndDirectorsWhoCooperatedAtLeastThreeTimes.py new file mode 100644 index 0000000..2e9f08e --- /dev/null +++ b/ActorsAndDirectorsWhoCooperatedAtLeastThreeTimes.py @@ -0,0 +1,10 @@ +''' +3 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: + actor_director = actor_director.groupby(['actor_id', 'director_id'])['timestamp'].count().reset_index() + res = actor_director[actor_director['timestamp']>=3] + return res[['actor_id', 'director_id']] \ No newline at end of file diff --git a/DailyLeadsAndPartners.py b/DailyLeadsAndPartners.py new file mode 100644 index 0000000..fcdb659 --- /dev/null +++ b/DailyLeadsAndPartners.py @@ -0,0 +1,12 @@ +''' +2 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: + daily_sales = daily_sales.groupby(['date_id', 'make_name']).agg( + unique_leads = ('lead_id', 'nunique'), + unique_partners = ('partner_id', 'nunique') + ).reset_index() + return daily_sales \ No newline at end of file diff --git a/GroupSoldProductsByTheDate.py b/GroupSoldProductsByTheDate.py new file mode 100644 index 0000000..52de225 --- /dev/null +++ b/GroupSoldProductsByTheDate.py @@ -0,0 +1,13 @@ +''' +Pandas10 + +1 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: + activities = activities.groupby('sell_date').agg( + num_sold = ('product', 'nunique'), + products = ('product', lambda x: ','.join(sorted(x.unique())))).reset_index() + return pd.DataFrame(activities) \ No newline at end of file