Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions S30_Pandas_01.py
Original file line number Diff line number Diff line change
@@ -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'})

_______________________________________________________________________________________________________________________________________________