0

I'm trying to access all the rows of a dataframe if the "match" column is "False".

Since I can't upload an image, I will explain the data. The dataframe has several columns, and I am only interested in the "match" column. I will keep all the rows when the "match" column's values are "False"

[enter image description here]

SyntaxError: invalid syntax
  • Welcome SIYAN. Instead of uploading the image, you could post the code. It helps others to copy and paste your code and run it locally. – gmauch Jul 12 '19 at 19:18
  • You must have hit your CAPS LOCK key prior to typing "fALSE" which is not a Python key word. Just need to change to "False" and that should clear your error. – mgrollins Jul 12 '19 at 23:34
  • You don't need to do this, this is what [**boolean filtering**](https://pandas.pydata.org/pandas-docs/stable/getting_started/10min.html#selection) by a logical expression is for: `df23[df23['match'] == False]` or `df23[~ df23['match']]` to be concise. – smci Jul 12 '19 at 23:34
  • 1
    @mgrollins: yes but the bigger picture is noone should ever write manual selection code like this when panads supports `df23[~ df23['match']]` i.e. Boolean indexing – smci Jul 13 '19 at 00:10
  • This is a duplicate, see [piRSquared's excellent answer](https://stackoverflow.com/a/46165056/202229) – smci Jul 13 '19 at 00:31
  • @smci I agree, but being new to pandas myself, there are so many mistakes one can make that obscure why a specific approach is or is not working, I just wanted to point it out. – mgrollins Jul 13 '19 at 00:36
  • 1
    @mgrollins: but when someone asks the right syntax to do something the wrong way, first tell them very loud and clear that it's the wrong way, tell them what the right way they need is, only then tell them "oh and by the way here's the syntax for what you were trying to do". Otherwise you only multiply confusion. There's too much of that in the pandas tag already. Also, this is a dupe. No point in answering dupes - they will get promptly closed. If they don't get promptly closed, come tell us in the [Python chatroom](https://chat.stackoverflow.com/rooms/6/python) – smci Jul 13 '19 at 00:39
  • Thanks for the advice @smci! I haven't used the chatroom, but I will give it a try in the future! – mgrollins Jul 13 '19 at 00:47
  • @mgrollins: Cool. Please skim the [Python chatroom rules](https://sopython.com/chatroom) before posting. – smci Jul 13 '19 at 00:48

1 Answers1

0

You don't need to do this, this is what boolean filtering by a logical expression is for:

df23[df23['match'] == False]

or to be more concise:

df23[~ df23['match']]
smci
  • 32,567
  • 20
  • 113
  • 146