I have the following dataset and I want to manually check with value in the column Name
is the same of the value in the column Factory
for the same rows.
I developed the following code reading the documentation around, but does not fully work. I want to make sure that there are the following characteristics:
- If I enter 1 it means that is all good, the name match and I can proceed to the next row
- If I enter 0 it means that the names do not match but I can anyway proceed to the next row
- If I enter 9 I am tired of checking and I want the whole loop to end.
- If I enter something that is not 1, 0 or 9, the loop asks me to re-enter the value
data = {'Name': ['Facotry One', 'Second value', 'Match'],
'Factory': ['Footwear Limited', 'Footweat not limited', 'Match']}
df_test = pd.DataFrame (data, columns = ['Name','Factory'])
df_test
english_matches = []
for index, row in df_test.iterrows():
print('Is ', row['Name'], ' the same as ', row['Factory' ])
while True:
try:
match = input("Enter 1 for match, 0 for mistmatch, 9 to exit the loop: ")
if match not in (1, 0, 9):
except ValueError:
print("Sorry, I didn't understand that.")
continue
else:
english_matches.append(match)
break
if match == 9:
Break
else:
print("You are still here")
Error
File "<ipython-input-16-81bdfa6d212f>", line 15
if match not in (1, 0, 9):
^
SyntaxError: invalid syntax