From 1a518cd71cef6424bc09b3e17e6f4b9e594f9921 Mon Sep 17 00:00:00 2001 From: Alok Tiwari Date: Wed, 2 Jul 2025 15:07:48 -0500 Subject: [PATCH 1/3] Your commit message here --- Pandas1 | 1 + 1 file changed, 1 insertion(+) create mode 160000 Pandas1 diff --git a/Pandas1 b/Pandas1 new file mode 160000 index 0000000..35b9ae1 --- /dev/null +++ b/Pandas1 @@ -0,0 +1 @@ +Subproject commit 35b9ae1c60d4d3967fe9593a93e08151969092bc From aa01fa7e3139ad26845c2f63453e75dade549c0b Mon Sep 17 00:00:00 2001 From: Alok Tiwari Date: Wed, 2 Jul 2025 15:33:29 -0500 Subject: [PATCH 2/3] testtt --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index a51355c..6ed07e5 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,17 @@ 1 Problem 1 : Make a Pandas DataFrame with two-dimensional list ( https://www.geeksforgeeks.org/make-a-pandas-dataframe-with-two-dimensional-list-python/) +# import pandas as pd +import pandas as pd + +# List1 +lst = [['Geek', 25], ['is', 30], + ['for', 26], ['Geeksforgeeks', 22]] + +# creating df object with columns specified +df = pd.DataFrame(lst, columns =['Tag', 'number']) +print(df ) + 2 Problem 2 :Big Countries ( https://leetcode.com/problems/big-countries/ ) 3 Problem 3 :Recyclable and Low Fat Products ( https://leetcode.com/problems/recyclable-and-low-fat-products/ ) From 88cd005f101984ffd2386cf999daf3fae862a21e Mon Sep 17 00:00:00 2001 From: Alok Tiwari Date: Wed, 9 Jul 2025 13:20:41 -0500 Subject: [PATCH 3/3] pandas-1 done --- README.md | 102 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 93 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6ed07e5..9958bd9 100644 --- a/README.md +++ b/README.md @@ -2,20 +2,104 @@ 1 Problem 1 : Make a Pandas DataFrame with two-dimensional list ( https://www.geeksforgeeks.org/make-a-pandas-dataframe-with-two-dimensional-list-python/) -# import pandas as pd -import pandas as pd - -# List1 -lst = [['Geek', 25], ['is', 30], - ['for', 26], ['Geeksforgeeks', 22]] +Create Pandas Dataframe from 2D List using pd.DataFrame() +In this example below code creates a Pandas DataFrame ('df') from a two-dimensional list ('lst') with specified column names ('Tag' and 'number') and prints the resulting DataFrame. +------------------------------------------------------ +import pandas as pd +lst = [['geek', 25], ['is', 30], + ['for', 26], ['Geeksforgeeks', 22]] +# creating df object with columns specified +df = pd.Dataframe(lst, columns=['Tag', 'number]) +print(df) +------------------------------------------------------ +#Create Pandas Dataframe from 2D List using pd.DataFrame.from_records() -# creating df object with columns specified -df = pd.DataFrame(lst, columns =['Tag', 'number']) -print(df ) +import pandas as pd +# Two-dimensional list +data = [['Geek1', 28, 'Analyst'], + ['Geek2', 35, 'Manager'], + ['Geek3', 29, 'Developer']] + +# Column names +columns = ['Name', 'Age', 'Occupation'] + +# Creating DataFrame using pd.DataFrame.from_records() +df = pd.DataFrame.from_records(data,columns=columns) + +print(df) + +------------------------------------------------------ +#Create Pandas Dataframe from 2D List using pd.DataFrame.from_dict() + +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) +------------------------------------------------------------ +#Create Pandas Dataframe from 2D List using Specifying Data Types + +import pandas as pd + +# Two-dimensional list +data = [['Geek1', 'Reacher', 25], + ['Geek2', 'Pete', 30], + ['Geek3', 'Wilson', 26], + ['Geek4', 'Williams', 22]] + +# Column names +columns = ['FName', 'LName', 'Age'] + +# Creating DataFrame with specified data types +df = pd.DataFrame(data, columns = columns) + +# Displaying the DataFrame +print(df) + + +------------------------------------------------------------ + +------------------------------------------------------ 2 Problem 2 :Big Countries ( https://leetcode.com/problems/big-countries/ ) +------------------------------------------------------------ +import pandas as pd + +def big_countries(world: pd.DataFrame) -> pd.DataFrame: + df = world[(world['area'] >= 3000000) | (world['population'] >= 25000000)] + #always give condition within () + return df[['name', 'population', 'area']] +------------------------------------------------------------------------------ 3 Problem 3 :Recyclable and Low Fat Products ( https://leetcode.com/problems/recyclable-and-low-fat-products/ ) +------------------------------------------------------------ +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"]] + + +------------------------------------------------------------ +------------------------------------------------------------ +------------------------------------------------------------ +------------------------------------------------------------------------------------------------------------------------ + 4 Problem 4 :Customer Who Never Order ( https://leetcode.com/problems/customers-who-never-order/ ) +import pandas as pd + +def find_customers(customers: pd.DataFrame, orders: pd.DataFrame) -> pd.DataFrame: + merged_df = customers.merge(orders, left_on='id', right_on='customerId', how='left') + return merged_df[merged_df['customerId'].isna()][['name']]