Hi everybody! I was curious on using the pandas library, so I took on this new project yesterday to get data from inside a spreadsheet based on an input. It searches for an email entry and returns all the user’s info, which is stored in the same row.
Major things I learnt were the .loc function to search for info and creating my own function with it to make the code smarter. A bit more boring than other projects but I’m looking forward to get more into working with pandas & data :)
You can try out the project here.
Important disclaimer: I’m interning at Abstra Cloud. I used it to generate UI bc right now I’m more focused on learning logic. I’ve been making most of my projects over there, but wanted to share bc it also would be cool for someone to make this elsewhere - in this case I believe using inputs and prints would be enough! Hope that’s fine.
Full code:
import pandas as pd
def get_cell(info):
return df.loc[df['Email'] == email, info].item()
df = pd.read_excel("data.xlsx")
email = read_email("What's your email?", initial_value = "roy@example.com")
result = df.loc[df['Email'] == email]
if email in result.values:
name = get_cell("Name")
points = get_cell("Points")
redeem_date = get_cell("Redeem date")
Page().display_markdown(f"""
# Hey {name}!
So far you've accumulated **{points}** points.
They can be reedemed from =={redeem_date}== onwards.""") \
.display("Here is your spreadsheet entry:") \
.display_pandas(result) \
.run()
else:
display('Sorry, can\'t find this user!')
Top comments (0)