0

I am writing a python script, where I use pymysql to connect to my MYSQL database and execute a query.

#sql query to get a list of country codes with country names    
query = ("SELECT MCC as 'MCC',Name as 'Name' FROM Enum.Country")
    cursor.execute(query)
    a = cursor.fetchall()
    print(a)
 #convert a to dataframe   
    df = pd.DataFrame(list(a),columns=["MCC","Name"])
    print(df)
#get the user input  
   user_input2 = raw_input("From the list, please enter the mcc of the country you want to create the service for:")

My data frame looks like:

     MCC                    Name
0    276                 Albania
1    603                 Algeria
2      0           All Countries
3    213                 Andorra
4    631                  Angola
5    722      Argentine Republic
6    283                 Armenia
7    505               Australia
8    232                 Austria
9    400              Azerbaijan

How can I check if the user_input2 is present in the dataframe df? Thanks In advance.

Ashu
  • 37
  • 1
  • 1
  • 9

1 Answers1

1

you can check like this,

 df.MCC.isin([user_input2]).any()
Pyd
  • 6,017
  • 18
  • 52
  • 109