-1

I don't kwnow why invalid syntax.

data[g in data.G.str.split(",") if (g.strip() == "H") else pass]

^
SyntaxError: invalid syntax

Thanks

tdelaney
  • 73,364
  • 6
  • 83
  • 116
  • Syntax errors can be in the lines above the error. A missing paren for example. Can you add the lines above this one for context? – tdelaney Apr 30 '18 at 04:50
  • Provide some data and explain your logic. I suspect there is a much better approach to this problem than what you are trying to accomplish with this errand statement. – Scott Boston Apr 30 '18 at 04:51
  • 1
    Is that really where the syntax error is? `else pass` doesn't make sense. Pass isnt a value. – tdelaney Apr 30 '18 at 04:56
  • I have a "data" with a column named G. it has string separated by ",". I need check in each row if contains a specify string, not only contains. that's why I need to use split. – Bárbara Silveira Fraga Apr 30 '18 at 11:41
  • Please edit your question according to the general guidelines here: https://stackoverflow.com/help/mcve – Paul H Apr 30 '18 at 14:11

1 Answers1

0

You can't use pass in this way.

I think what you want is:

data[(g.strip() == "H") & (g in data.G.str.split(","))]

see here to understand the syntax: Python Ternary Operator Without else

Ludo
  • 2,307
  • 2
  • 27
  • 58