buschbirk / intro-data-capstone-musclehub

0 stars 0 forks source link

Incorrect test for None #10

Closed hillarygreenlerman closed 6 years ago

hillarygreenlerman commented 6 years ago

https://github.com/buschbirk/intro-data-capstone-musclehub/blob/66253a292dbe1c2e164ec5b57ff40c1a6da26ecf/Final%20Analysis/musclehub.py#L213

None objects are tricky. There are several correct ways to test for them:

  1. Using is
    foo = None
    print(foo is None)
    >> True
  2. In Pandas, we can also use isnull:
    import pandas as pd
    foo = None
    print(pd.isnull(foo))
    >> True

    This idiom is particularly nice when testing an entire column in a DataFrame.

This StackOverflow article goes into more detail about why is syntax is preferred: https://stackoverflow.com/questions/3965104/not-none-test-in-python