0
votes

I'm trying to use a select query to select a currency code (USD, GBP etc) from a database and use it to go straight into a converter. Instead of just getting 'USD' etc, I get a little table that looks like:

Currency
0 GBP

Is there a way to just return 'GBP'? The current query result doesn't work in my converter. I've tried printing it normally and I've tried printing it as a string. Thank you!

My code is:

a = input("Enter ID of sending customer: ") 
a2 = pd.read_sql("SELECT Currency FROM Customers WHERE \
                 ID='{}'".format(a), con)
print(str(a2))
print(a2)
2

2 Answers

0
votes

Are you using SQLITE3 to handle your database? If so, it is way better to extract data from the table according to the official documentation, using a cursor and the fetchall() method. You can find more details here https://www.sqlitetutorial.net/sqlite-python/sqlite-python-select/

0
votes

The read_sql method returns a dataframe so you'll have to get the column you want from that dataframe. Something like:

currency = a2['Currency']