Skip to content
Open
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions Problem1_2DList.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pandas as pd

# Two-dimensional list
data = [['Geek1', 26, 'Scientist'],
['Geek2', 31, 'Researcher'],
['Geek3', 24, 'Engineer']]

# Column names
columns = ['Name', 'Age', 'Occupation']

# Creating DataFrame using pd.DataFrame.from_dict()
df = pd.DataFrame.from_dict(dict(zip(columns, zip(*data))))

# Displaying the DataFrame
print(df)
5 changes: 5 additions & 0 deletions Problem2_BigCountry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import pandas as pd

def big_countries(world: pd.DataFrame) -> pd.DataFrame:
df=world[(world['area']>=3000000) | (world['population']>=25000000)]
return pd.DataFrame(df[['name','population','area']])
5 changes: 5 additions & 0 deletions Problem3_Recyclable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import pandas as pd

def find_products(products: pd.DataFrame) -> pd.DataFrame:
df=products[(products['low_fats']=='Y') & (products['recyclable']=='Y')]
return pd.DataFrame(df[['product_id']])
15 changes: 15 additions & 0 deletions Problem4_CustomerNoOrder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pandas as pd

#Soln 1: Using Merge
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['id_y'].isnull()]
print(df[['name']])
return pd.DataFrame(df[['name']]).rename(columns={'name':'Customers'})

#Soln 2: Using isin()
df=customers[~customers['id'].isin(orders['customerId'])]
return pd.DataFrame(df[['name']]).rename(columns={'name':'Customers'})