diff --git a/2d Dimentional.sql b/2d Dimentional.sql new file mode 100644 index 0000000..0093c93 --- /dev/null +++ b/2d Dimentional.sql @@ -0,0 +1,17 @@ +#List to DF +import pandas as pd + +def big_countries(world: pd.DataFrame) -> pd.DataFrame: + lst=[["sonu",26],["maggi",25],["pooja",27]] + #print(type(df)) + return pd.DataFrame(lst,columns=["Name","Age"]) + + + +#Dict to DF +import pandas as pd + +def big_countries(world: pd.DataFrame) -> pd.DataFrame: + data={"name":["sonu","pooja","maggi"],"age":[26,27,25]} + #print(type(data)) + return pd.DataFrame(data).rename(columns={"name":"nam","age":"ah"}) \ No newline at end of file diff --git a/BigCountries.sql b/BigCountries.sql new file mode 100644 index 0000000..675d7b8 --- /dev/null +++ b/BigCountries.sql @@ -0,0 +1,7 @@ +import pandas as pd + +def big_countries(world: pd.DataFrame) -> pd.DataFrame: + df=world[(world["area"]>=3000000)|(world["population"]>=25000000)] + df=df[["name", "area", "population"]] + return df + diff --git a/CustomersWhoNeverOrder.sql b/CustomersWhoNeverOrder.sql new file mode 100644 index 0000000..a8d5d79 --- /dev/null +++ b/CustomersWhoNeverOrder.sql @@ -0,0 +1,14 @@ +import pandas as pd + +def find_customers(customers: pd.DataFrame, orders: pd.DataFrame) -> pd.DataFrame: + df=customers[~customers["id"].isin(orders["customerId"])] + return df[["name"]].rename(columns={"name":"Customers"}) + + +#2nd method using merge +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"}) \ No newline at end of file diff --git a/Recyclable.sql b/Recyclable.sql new file mode 100644 index 0000000..7363190 --- /dev/null +++ b/Recyclable.sql @@ -0,0 +1,6 @@ +import pandas as pd + +def find_products(products: pd.DataFrame) -> pd.DataFrame: + df=products[(products["low_fats"]=="Y") & (products["recyclable"]=="Y")] + df=df[["product_id"]] + return df \ No newline at end of file