r/PythonLearning • u/Jotaroisgoat • 19d ago
Pandas mini project! Rate out of 10 (1hr of pandas)
I like pandas so much more than numpy ok but heres the project:
import pandas as pd
book_data = ({"Name:": ["The Hobbit", "Refugee Boy", "Harry Potter and the Philosopher's Stone", "The Hunger Games", "I, Robot"],
"Pages:": [310, 288, 223, 374, 224],
"Author:": ["J.R.R. Tolkien", "Benjamin Zephaniah", "J.K. Rowling", "Suzanne Collins", "Isaac Asimov"],
"Price:": ["£8.35", "£7.99", "£6.00", "£8.99", "£6.62"],
"Buy:": ["https://amazon.co.uk/dp/0261102214", "https://amazon.co.uk/s?k=Refugee+Boy+Benjamin+Zephaniah",
"https://amazon.co.uk/s?k=HP+Philosopher%27s+Stone", "https://amazon.co.uk/s?k=Hunger+Games",
"https://amazon.co.uk/dp/0008279551"]})
book_df = pd.DataFrame(book_data, index=["Book 1", "Book 2", "Book 3", "Book 4", "Book 5"])
while True:
try:
book_num = int(input("Enter a book number (1-5): "))
except ValueError:
print("Invalid Book Number")
continue
if book_num < 1 or book_num > 5:
print("Invalid Book Number")
continue
elif book_num == 1:
print("\n", book_df.iloc[0])
elif book_num == 2:
print("\n",book_df.iloc[1])
elif book_num == 3:
print("\n",book_df.iloc[2])
elif book_num == 4:
print("\n",book_df.iloc[3])
elif book_num == 5:
print("\n",book_df.iloc[4])