-2
data = input_data[~input_data.MAKE.isnull()]

I am new to python and have been learning the basics for a week. I am now working on certain data science projects using my basic skills. I have the above line in a Python tutorial that I'm going through and I'm not sure what it does. Can anyone help me with it?

Stefan van den Akker
  • 6,661
  • 7
  • 48
  • 63
  • Could you provide a little bit more context? Like a minimal working example? – Stefan van den Akker Jun 04 '14 at 06:27
  • 1
    Context would be great indeed. About the tild though: http://stackoverflow.com/q/8305199/1524913 – jeromej Jun 04 '14 at 06:32
  • 1
    This is the tutorial you are talking about: http://nbviewer.ipython.org/urls/s3.amazonaws.com/datarobotblog/notebooks/Getting%20Started%20with%20Data%20Science.ipynb What precisely do you find confusing about it? Which parts do you understand, and which do you not? – jonrsharpe Jun 04 '14 at 06:34

1 Answers1

1

The tilde '~' is the "bitwise complement" operator; per the Python wiki:

~ x

Returns the complement of x - the number you get by switching each 1 for a 0 and each 0 for a 1. This is the same as -x - 1.

input_data.MAKE.isnull() will give you the rows that contain nulls in MAKE, so the complement is the rows that do not, therefore:

data = input_data[~input_data.MAKE.isnull()]

will index the input_data by rows where MAKE isn't null, i.e. drop all of the rows where it is null.

Community
  • 1
  • 1
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437