Pandas.DataFrame.query Series.str.startswith Tuple returns Empty


In the following example, the final DataFrame returns empty — what am I missing?

df = pd.DataFrame({
df1 = df['01',na=False)]
df2 = df['01','03'),na=False)]
df3 = df.query("foo.str.startswith('01',na=False)")
df4 = df.query("foo.str.startswith(('01','03'),na=False)")
Asked By: jbeckom



Apparently using a @ resolves this issue with a tuple defined before hand like:

t = ('01', '03')

df.query("foo.str.startswith(@t, na=False)")


    foo bar
0   010 aaa
2   030 ccc

From query doc:



    The query string to evaluate.

    You can refer to variables in the environment by prefixing 
    them with an ‘@’ character like @a + b.
Answered By: SomeDude
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.