0

im trying to read a csv file in python, then save the contents of csv file into list so that i can then search within that list to see if it matches the input from the user.

here is what i have so far . my code keeps skipping to the else block even if the input matches the number in csv file.

data = []

with open ("numbers.csv", "r") as file:
    reader = csv.reader(file)
    
    for row in reader:
        data.append(row)

if input in data:
   print("success")

else: 
   print("no match")
4

1 回答 1

0
import pandas as pd

df = pd.read_csv("file.csv")
data = df.values.tolist()

if input in data:
   print("success")

else: 
   print("no match")
于 2020-11-14T18:25:49.690 回答