Converting string into condition for pandas dataframe

后端 未结 1 1402
孤城傲影
孤城傲影 2021-01-27 01:32

I have a condition for a pandas dataframe written in a string. Something like this:

\"(data[\'Variable1\'] == 1) & (data[\'Variable2\'] == 2)\"
相关标签:
1条回答
  • 2021-01-27 02:11

    You can use pandas query to filter required rows

    your_query_string = "Variable1 == 1 & Variable2 == 2"
    data = data.query(your_query_string)
    
    0 讨论(0)
提交回复
热议问题