2

This doesn't work:

df.query('`Record Type` == "Keyword" &
         `Campaign Status` == "enabled"')

But this does:

df.query('`Record Type` == "Keyword" & \
        `Campaign Status` == "enabled"')

There are times when I don't use a \ within the parentheses of a function and it seems to work, and other times it doens't, and I am not able to identify why. My understanding was that there could be line breaks without a \ if there are parentheses surrounding the statement, but obviously my understanding is incorrect...

intedgar
  • 631
  • 1
  • 11
ah2Bwise
  • 82
  • 2
  • 17
  • Both statements should work just fine, and they work for me. You can have embedded newlines inside any set of brackets (round, square, or curly). If you're getting a syntax error, please post it. – Tim Roberts Nov 05 '21 at 19:46
  • 4
    Your linebreak is inside a `''` string literal, as indicated by the `SyntaxError: EOL while scanning string literal` that you should be getting. If you want to do a multiline string literal, use `""""""`. If you don't want the linebreak inside the string itself, end the string with a closing quote, and continue on the next line in a new string literal. – Samwise Nov 05 '21 at 19:49
  • pandas does not support multi-line queries. @Samwise advice to use triple quotes won't help. https://stackoverflow.com/questions/63597476/pandas-dataframe-multiline-query – Ufos Nov 06 '21 at 20:38

0 Answers0