I am using Pandas to access a CSV file I have created. I have created a list using the data.name.tolist() function, called "IDs", storing all the ID numbers of the users (currently these ID's are 1-6, but will later become 5 digit numbers), What I wish to do, is to compare the entered ID number with the list of IDs, and provide an output based on whether the entered ID is in the list. What would be the best possible method for doing so?
colnames = ['name', 'ID', 'carPass', 'cardLost']
data = pandas.read_csv('info.csv', names = colnames)
IDs = data.ID.tolist()
#Asks the user what their ID Number is
entry = int(input("What is your id number?")).strip()
if entry isin IDs:
name,ID,carPass,cardLost dog,34,yes,yes cat,78,yes,no bird,45,no,no lizard,84,no,yes
This should be enough of a boolean to find the entries with ID number.
import pandas as pd df = pd.read_csv("info.csv") entry = int(input("What is your id number? ")) if entry in df["ID"].tolist(): print(df[df["ID"] == entry]) else: print("No entries with that ID number.")