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
5 changes: 5 additions & 0 deletions BigCountries.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 df[['name','population','area']]
5 changes: 5 additions & 0 deletions CustomersWhoNeverOrder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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'})
62 changes: 62 additions & 0 deletions MakeAPandasDataframeWithTwo-DimensionalLists.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#Q1
#Create Pandas Dataframe from 2D List using pd.DataFrame()

import pandas as pd

list_1 = [['Geek', 25],
['is', 30],
['for', 26],
['Geeksforgeeks', 22]]

# creating df object with columns specified
df = pd.DataFrame(list_1, columns =['Tag','number'])
print(df )


#Q2
#Create Pandas Dataframe from 2D List using pd.DataFrame.from_records()

import pandas as pd

data = [['Geek1', 28, 'Analyst'],
['Geek2', 35, 'Manager'],
['Geek3', 29, 'Developer']]

columns = ['Name', 'Age', 'Occupation']

# Creating DataFrame using pd.DataFrame.from_records()
df = pd.DataFrame.from_records(data, columns=columns)
print(df)


#Q3
#Create Pandas Dataframe from 2D List using pd.DataFrame.from_dict()

import pandas as pd

data = [['Geek1', 26, 'Scientist'],
['Geek2', 31, 'Researcher'],
['Geek3', 24, 'Engineer']]

columns = ['Name', 'Age', 'Occupation']

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



#Q4
#Create Pandas Dataframe from 2D List using Specifying Data Types
import pandas as pd

data = [['Geek1', 'Reacher', 25],
['Geek2', 'Pete', 30],
['Geek3', 'Wilson', 26],
['Geek4', 'Williams', 22]]

columns = ['FName', 'LName', 'Age']

# Creating DataFrame with specified data types
df = pd.DataFrame(data, columns=columns)
print(df)
5 changes: 5 additions & 0 deletions RecyclableAndLowFatProducts.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 df[['product_id']]