From 254310e7437217456ec4db6d3d276f2d11dfd630 Mon Sep 17 00:00:00 2001 From: Nidhi Chauhan <61177315+ni-13@users.noreply.github.com> Date: Wed, 5 Mar 2025 12:45:16 -0500 Subject: [PATCH] Completed_S30_Pandas1 --- S30_Pandas_01.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 S30_Pandas_01.py diff --git a/S30_Pandas_01.py b/S30_Pandas_01.py new file mode 100644 index 0000000..df3acc4 --- /dev/null +++ b/S30_Pandas_01.py @@ -0,0 +1,53 @@ +#Pandas_01 +_______________________________________________________________________________________________________________________________________________ + +# 595. Big Countries_ Solution_Q1 + +import pandas as pd + +def big_countries(world: pd.DataFrame) -> pd.DataFrame: + df= world[(world['area']>=3000000)| (world['population']>= 25000000)] + df= df[['name','population', 'area']] + return df + +# Alternative1 + +import pandas as pd + +def big_countries(world: pd.DataFrame) -> pd.DataFrame: + return world[(world["area"] >= 3000000) | (world["population"] >= 25000000)][["name", "population", "area"]] + +_______________________________________________________________________________________________________________________________________________ + +# 1757. Recyclable and Low Fat Products_Solution_Q2 + +import pandas as pd + +def find_products(products: pd.DataFrame) -> pd.DataFrame: + df = products[(products['low_fats']== 'Y') & (products['recyclable']== 'Y')] + return df[['product_id']] + +_______________________________________________________________________________________________________________________________________________ + +# 183. Customers Who Never Order_Solution_Q3 + +import pandas as pd + +def find_customers(customers: pd.DataFrame, orders: pd.DataFrame) -> pd.DataFrame: + + df = customers.merge(orders, left_on='id', right_on='customerId', how='left') + df = df[df['customerId'].isna()] + df = df[['name']].rename(columns={'name': 'Customers'}) + +# Alternative1 + +import pandas as pd + +def find_customers(customers: pd.DataFrame, orders: pd.DataFrame) -> pd.DataFrame: + + df= customers.merge(orders, left_on ='id', right_on='customerId', how='left') + df=df[df['customerId'].isna()] + return df[['name']].rename(columns= {'name': 'Customers'}) + +_______________________________________________________________________________________________________________________________________________ +