我正在编写一个python脚本,我使用pymysql连接到我的MYSQL数据库并执行查询。
#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:")
我的数据框架如下:
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
如何检查user_input2是否存在于数据框df中? 在此先感谢。
答案 0 :(得分:0)
你可以这样检查,
df.MCC.isin([user_input2]).any()