-1

I wonder how to extract only rows whose column is notnull and put them in a variable. My code is

data_result = df[df['english'].isnull().sum()==0]

But an Error accured. How do I fix it?

Dataframe:

   name  math  english             
0  John  90    nan              
1  Ann   85    84                
2  Brown 77    nan               
3  Eva   92    93                
4  Anita 91    90
5  Jimmy 75    69

Result

name  math  english
1  Ann   85    84
3  Eva   92    93
4  Anita 91    90
5  Jimmy 75    69
Code Different
  • 90,614
  • 16
  • 144
  • 163

1 Answers1

0

Try this:

data_result = df[df['english'].notnull()]
Code Different
  • 90,614
  • 16
  • 144
  • 163
  • But an error accured. --------------------------------------------------------------------------- IndexingError Traceback (most recent call last) in 2 3 # df[df['english'].isnull().sum()==0] ----> 4 data_result = df[df['english'].notnull()] 5 data_result ..... IndexingError: Unalignable boolean Series provided as indexer (index of the boolean Series and of the indexed object do not match). – kokomong Jan 12 '20 at 14:42
  • `df['english'].isnull().sum()` return a scalar value, and you need performance a boolean indexing: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#boolean-indexing @Yang Yang – ansev Jan 12 '20 at 23:47