Retrieving data from Pandas based on iloc and user input
<p>I have a small SQLite DB with data about electrical conductors. The program prints the list of names and Pandas ID, accepts user input of that ID, and then prints all the information about the selected conductor.</p>

<p>I am trying to figure out how to then select a specific item from a specified column - later, I'll allow input, but for now, I'm just manually specifying in the print() to simplify troubleshooting for myself.</p>

<p>The program works up until the combined conditional print line. I suspect casting the string to the int is making this more difficult than it needs to be; if there's a better way to select an entry (for instance, just matching the name given to the name in the db), I'm open to that.</p>

<pre><code>with lite.connect(db_path) as db:

df = pd.read_sql_query('SELECT * FROM cond', conn)
print('What conductor are you analyzing?')

try:
    print(pd.read_sql_query('SELECT name FROM cond', conn)) # List names and Pandas IDs
    getCond = int(input('\nEnter the ID #: ')) # cast string to int to allow .iloc
    printSel = df.iloc[getCond]
    print()
    print(printSel)
    print(df[(df['Amps']) &amp; (df.iloc == getCond)])

finally:
    if conn:
        conn.close()
</code></pre>

<p>EDIT: The error thrown after selecting an item is </p>

<p>"TypeError: cannot compare a dtyped [object] array with a scalar of type [bool]"</p>

<p>I'm at a loss, because I think it's saying the &amp; operator is being compared to something, rather than using it as print whatever meets "This AND That."</p>

<p>If I understand correctly, the 'getCond' will be the index of the row you want to select, and 'Amps' is the column. I think you can just do this to return the 'getCond' row of the 'Amps' column.</p>

<p>df.loc[getCond, 'Amps']</p>

python sqlite pandas