Home > Mobile >  Pandas subset selection and Pep8
Pandas subset selection and Pep8

Time:11-16

I am using Spyder IDE with code style warnings enabled. Selecting a subset from a Pandas dataframe via df[df['Col1'].isna() == False] triggers the following code style warning.

enter image description here

The code analysis suggests using if. However, if does not work in this context. How do I select a subset from a Pandas dataframe without triggering a code style warning?

CodePudding user response:

For inverse mask in pandas is used ~ instead compare False:

df[~df['Col1'].isna()]

Or use Series.notna:

df[df['Col1'].notna()]

Your error is for pure python, not for pandas.

CodePudding user response:

Use notna:

df[df['Col1'].notna()]

Or you could invert the mask with ~ (vectorized NOT operator):

df[~df['Col1'].isna()]
  • Related