Anish
Anish

Reputation: 31

How to I filter summed rows with a condition in a Pandas DataFrame?

I essentially want to display only those features in the dataset that have number of null values > 0.

The line of code:

train_df.isnull().sum()

Output is:

Id                  0
MSSubClass          0
MSZoning            0
LotFrontage       259
LotArea             0
Street              0
Alley            1369
...

I am unable to modify the code to show only the features where the values in more than 0 (or any other condition).

Thank you!

Upvotes: 1

Views: 316

Answers (1)

frankr6591
frankr6591

Reputation: 1247

Here is an example:

d = dict(Id        = 0,
MSSubClass         = 0,
MSZoning           = 0,
LotFrontage        = 259,
LotArea            =  0,
Street             =  0,
x               = -1,
Alley            = 1369)
df = pd.DataFrame([d],index=['value']).transpose()
df

output

            value
Id          0
MSSubClass  0
MSZoning    0
LotFrontage 259
LotArea     0
Street      0
x           -1
Alley       1369

To filter non-null values > 0 :

df[df.value > -1]

Upvotes: 1

Related Questions