Unable to query a local variable in pandas 0.14.0

前端 未结 2 1679
北荒
北荒 2020-12-10 12:57

I can query an explicit value:

fills.query(\'Symbol==\"BUD US\"\')

Now I want to query a variable:

In [40]: my_symbol
Out[4         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-10 13:34

    The above answer is pretty much right on, but wanted to mention another workaround that I've used in this situation. Basically, just treat the query string like you would any other string where you'd want to insert a variable.

    my_symbol = 'BUD US'
    fills.query("Symbol=='{0}'".format(my_symbol))
    

    edit: fixed per your comment

提交回复
热议问题