'Select a value from a specific column and row
I'm storing the result of a SQL Query in a DataFrame and I just don't understand how can I get a specific value. I have the following code:
for date in years:
partyList = pd.read_sql_query(
"SELECT top 2 country_name,election_date,party_name_english, vote_share, left_right FROM view_election WHERE country_name_short like '" + country + "' and election_date like '" + date + "' ORDER BY vote_share DESC",
conn)
parties = str(partyList).replace(" ", "").split()
parties.remove(parties[0])
format(parties)
# print(partyList)
total = total.append(partyList)
print(total.iloc[0, 0:1])
The output is:
country_name Slovakia
Name: 0, dtype: object
How can I get the String "Slovakia" to a variable? I want to understand how I do it so I can use it for other values as well
Also, How can I store an entire row into a "normal" array? I'm asking this just because I find it easier to work with regular arrays
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
