Ashwini Khare
Ashwini Khare

Reputation: 1675

Pandas Apply function on Column

I have a few columns in the Pandas dataframe which are sparsely populated, and I wish to modify their respective values to, whether they are filled or not.

For instance, my dataframe is:

      A  B  C  D
   0  8        8
   1  9  4     4
   2  5     3  8
   3  4        1 

I want it to be :

      A  B  C  D
   0  8  F  F  8
   1  9  T  F  4
   2  5  F  T  8
   3  4  F  F  1 

F = False, T= True

Running pandas.isnull(df['B']) returns a new series with boolean values, how do I update it efficiently in the original dataframe?

Upvotes: 0

Views: 119

Answers (1)

BrenBarn
BrenBarn

Reputation: 251345

You can just do df['B'] = df.B.notnull().

Upvotes: 4

Related Questions