How do I refer to an unnamed DataFrame column in a query string when using pandas.DataFrame.query? I know I can to column names that are not valid Python variable names by surrounding them in backticks. However, that does not address unnamed columns.
For example, I would like to query for all rows in a DataFrame where an unnamed column contains a value greater than 0.5.
My code starts like:
import pandas as pd
import numpy as np
array=np.random.rand(10,3)
df=pd.DataFrame(array)
so far so good but then when I try to use pandas.DataFrame.query what query string should I use to find rows where the value in the second column (which happens to unnamed) are greater than 0.5 ?
The closest thing I can think of is
df.query('columns[1]>0.5')
which is flat out wrong because columns columns[1] returns the column number, 1, and does not reference the unnamed column.
I have looked at the Pandas documentation including
https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.query.html#pandas.DataFrame.query
https://pandas.pydata.org/docs/user_guide/indexing.html#indexing-query
Any ideas?