Little did I know at first. I thought I could just use an f string. After reading about insertion attacks (by reading I mean a stick-man comic strip) and about SQLite parameters with the dangling comma, I have this.
stat_field = input("Enter stat field: ")
query = "SELECT player_name, (?) FROM stattable"
conn = sqlite3.connect('pitches.db')
df = pd.read_sql_query(query, conn, params=(stat_field,))
conn.close()
If I type 'pfx_x' at the prompt, a column in stattable, the dataframe looks like this.
player_name (?)
0 Mike Mayers pfx_x
1 Mike Mayers pfx_x
2 Mike Mayers pfx_x
Any idea how to get the actual data for that last column?
pfx_xinto the query string, it will work of course. But binding isn't the same as f-string interpolation. It only works on variables related to values in the table, not the query itself, if I understand correctly. So binding will work if you sayWHERE player_name=?and pass in"Mike Mayers"as the bound variable but you can't saySELECT * FROM ?;and try to bind that with"stattable". See this even though it's not SQLite, it should still apply.