1

I want to drop all rows that are zero in the "feet" column.

df['feet'] = df['feet'][(df != 0).all(1)]


dataset.info()

the above code gives such a result:

col1 8640 non-value object
col2 8640 non-value object
col3 8640 non-value object
col4 8640 non-value object
feet 7640 non-value object

As you can see, the code correctly remove the values ​​in the 'feet' column, but I also want it to delete the rows in all columns where 'feet' = 0

I can do it easily with Numpy but I want to know how it can be done without it.

2 Answers 2

2

You need boolean indexing:

df1 = df[df['feet'] != 0]

Or DataFrame.query:

df1 = df.query("feet != 0")
Sign up to request clarification or add additional context in comments.

3 Comments

This is not the point. I want to delete all rows in all columns but only those with zeros in the 'feet' column
@tbone - Sorry, answer was changed.
@ansev - Interesting, I check time of edit and your time of answer and your was one minute later... Not sure why
1

use this:

df[df['feet'].ne(0)]

or

df[df['feet'] != 0]

or

df[~(df['feet'] == 0)]

df[~(df['feet'].eq(0))]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.