Could I get a little help on what I'm sure's a simple solution. I've looked around here and online and not been able to solve it. I'm less than a week old in to this and have basically set myself a little task to learn some of the basics.
import pandas as pd
df1 = pd.read_csv('booking.csv', names=['snum','booked','name'])
df1.drop(['booked', 'name'], axis=1, inplace=True)
df2 = df1.values.tolist()
print('The following tickets are available; %s' % df2)
tic = input('Which ticket would you like to buy? ')
if tic in df2:
print('Ok')
else:
print('Ticket Unavilable')
The problem I'm having is with the If statement. No matter what value I use as the input I always get the message 'Ticket Unavailable'. I belive the error must lie with the list that has been coverted from the dataframe.
So far I've;
- Tested the IF statement aggainst a List that hasn't been converted or imported and that worked as expected
- 'Printed' the df2 variable type to confirm it is a list
- The df2 variables appear in the printed question so I know they've been imported and converted across ok
- Copy and pasted in to a different Python file with the same result
The variables are basic seat numbers A1, A2, A3, A4, A5, B1, B2, B3, B4, B5. I'm aware an input of 'A' 'B' ect would also return 'OK', the practicality isn't as important as functionality.
Aucun commentaire:
Enregistrer un commentaire