From d0d93eed9d55fc7b663b163bac03155e669576aa Mon Sep 17 00:00:00 2001 From: Pranathi Date: Thu, 19 Jun 2025 18:26:10 -0700 Subject: [PATCH] Pandas10 Submitted --- Problem1.py | 8 ++++++++ Problem2.py | 5 +++++ Problem3.py | 6 ++++++ 3 files changed, 19 insertions(+) create mode 100644 Problem1.py create mode 100644 Problem2.py create mode 100644 Problem3.py diff --git a/Problem1.py b/Problem1.py new file mode 100644 index 0000000..777dc27 --- /dev/null +++ b/Problem1.py @@ -0,0 +1,8 @@ +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(set(x)))) + ).reset_index() + return activities.sort_values(by = ['sell_date']) \ No newline at end of file diff --git a/Problem2.py b/Problem2.py new file mode 100644 index 0000000..d39cae5 --- /dev/null +++ b/Problem2.py @@ -0,0 +1,5 @@ +import pandas as pd + +def daily_leads_and_partners(daily_sales: pd.DataFrame) -> pd.DataFrame: + daily_sales_1 = daily_sales.groupby(['date_id','make_name'])[['lead_id','partner_id']].nunique().reset_index() + return daily_sales_1.rename(columns = {'lead_id':'unique_leads','partner_id':'unique_partners'}) \ No newline at end of file diff --git a/Problem3.py b/Problem3.py new file mode 100644 index 0000000..e1f2ab4 --- /dev/null +++ b/Problem3.py @@ -0,0 +1,6 @@ +import pandas as pd + +def actors_and_directors(actor_director: pd.DataFrame) -> pd.DataFrame: + df = actor_director.groupby(['actor_id', 'director_id']).size().reset_index(name = 'count') + df = df[df['count']>=3] + return df[['actor_id','director_id']] \ No newline at end of file