lundi 16 mars 2020

If statement using a pandas column as a condition and the users´ input

I´m having lots of problems to solve this: I want to use the users input to search in a data set and give the users the complete row that´s the same of it´s input. The code I´ve done is something like that, but I don´t know how to fix the problems in the if statement, any suggestion´ll be great.

import pandas as pd

a = pd.read_csv('data.txt', delimiter = '\t')

pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
pd.set_option('display.max_colwidth', None)

a.set_index('Rank', inplace = True)
user_rank = input('Choose the rank: ')

if int(user_rank) == all(a.iloc['Rank']):
  print(a.loc[user_rank])
else:
  print('Error')

Aucun commentaire:

Enregistrer un commentaire