import pandas as pd
def menu():
while True:
print("\n______MENU______")
print("1. Extract row wise")
print("2. Row Wise Series Object(iterrows()).")
print("3. Exit")
option = int(input("Enter the valid option [1 - 3] : "))
if option > 3 or option < 1:
print("Invalid entry. Try again")
continue
break
return option
def main():
# creating the dataframe
# initialize list
data = [['TOM', 10], ['RIDDLE', 15], ['JESSE', 14]]
# Create the pandas DataFrame
df = pd.DataFrame(data, columns=['Name', 'Age'])
print("The dataframe is : ")
print(df)
while True:
option = menu()
if option == 3:
print("Exiting the program")
break
if option == 1:
# extract row wise
# iterating directly using the index
for i in df.index:
print("Name : ", df['Name'][i], "\tAge : ", df['Age'][i])
else:
# extract series object
for index, row in df.iterrows():
print(row["Name"], row["Age"])
main()
OUTPUT:
Comments
Leave a comment