One-liner. No transpose needed:

df.loc[~(df == 0).all(axis=1)]

And for those who like symmetry, this also works...

df.loc[(df != 0).any(axis=1)]
Answer from 8one6 on Stack Overflow
Discussions

python - Delete Pandas DataFrame row where column value is < 0 - Stack Overflow
I already read the answers in this thread but it doesn't answer my exact problem. My DataFrame looks like this Lady in the Water The Night Listener Just My Luck Correlation More on stackoverflow.com
🌐 stackoverflow.com
python - How to remove rows from a DataFrame where some columns only have zero values - Stack Overflow
If you print my_query it is easy to read: ~(c==0 and d==0 and e==0 and f==0) with ~ means 'not'. ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... Introducing Stack Internal: Powering the human intelligence layer of... ... 2 How to remove rows where all numerical columns contain zero in Pandas Dataframe with mixed type of columns? 0 Remove several rows with zero values in a dataframe using python... More on stackoverflow.com
🌐 stackoverflow.com
Python: drop value=0 row in specific columns - Stack Overflow
I want to drop rows with zero value in specific columns >>> df salary age gender 0 10000 23 1 1 15000 34 0 2 23000 21 1 3 0 20 0 4 28500 ... More on stackoverflow.com
🌐 stackoverflow.com
python - Filter out rows/columns with zero values in MultiIndex dataframe - Stack Overflow
I have the following panda MultiIndex dataframe in python 0 1 2 3 bar one 0.000000 -0.929631 0.688818 -1.264180 two 1.130977 0.063277 0.161366 0.59... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Skytowner
skytowner.com › explore › removing_rows_with_all_zeros_in_pandas_dataframe
Removing rows with all zeros in Pandas DataFrame
Since we want the rows that are not all zeros, we must invert the booleans using ~: ... Finally, we pass this boolean mask into df[~] to fetch all the rows corresponding to True in the mask: ... Checks each row or column, and returns True for that row/column if all its values evaluate to True.
Find elsewhere
Top answer
1 of 2
13

I think you need create boolean DataFrame by compare all filtered columns values by scalar for not equality and then check all Trues per rows by all:

df = df[(df[['A','C']] != 0).all(axis=1)]
print (df)
   A  B  C
0  1  2  5
2  6  8  4

Details:

print (df[['A','C']] != 0)
       A      C
0   True   True
1   True  False
2   True   True
3  False   True

print ((df[['A','C']] != 0).all(axis=1))

0     True
1    False
2     True
3    False
dtype: bool

I think you need create boolean DataFrame by compare all values by scalar and then check any Trues per rows by any and last invert mask by ~:

df = df[~(df[['A','C']] == 0).any(axis=1)]

Details:

print (df[['A','C']])
   A  C
0  1  5
1  4  0
2  6  4
3  0  2

print (df[['A','C']] == 0)
       A      C
0  False  False
1  False   True
2  False  False
3   True  False

print ((df[['A','C']] == 0).any(axis=1))
0    False
1     True
2    False
3     True
dtype: bool

print (~(df[['A','C']] == 0).any(axis=1))
0     True
1    False
2     True
3    False
dtype: bool
2 of 2
5

One line hack using .dropna()

import pandas as pd

df = pd.DataFrame({'A':[1,4,6,0],'B':[2,4,8,4],'C':[5,0,4,2]})
print df
   A  B  C
0  1  2  5
1  4  4  0
2  6  8  4
3  0  4  2

columns = ['A', 'C']
df = df.replace(0, pd.np.nan).dropna(axis=0, how='any', subset=columns).fillna(0).astype(int)

print df
   A  B  C
0  1  2  5
2  6  8  4

So, what's happening is:

  1. Replace 0 by NaN with .replace()
  2. Use .dropna() to drop NaN considering only columns A and C
  3. Replace NaN back to 0 with .fillna() (not needed if you use all columns instead of only a subset)
  4. Correct the data type from float to int with .astype()
🌐
sqlpey
sqlpey.com › python › pandas-filtering-rows-equal-zero
Pandas DataFrame Row Filtering Techniques: Removing Rows Where Column Equals Zero
October 29, 2025 - To keep rows where line_race is not equal to zero, we use the inequality operator !=. # Solution 1: Simple Boolean Masking df_filtered_1 = df[df['line_race'] != 0] A Note on Null Values: It is crucial to recognize that direct comparison with Python’s None does not behave as expected in Pandas ...
🌐
Shane Lynn
shanelynn.ie › home › delete rows & columns in dataframes quickly using pandas drop
Delete Rows & Columns in DataFrames using Pandas Drop
December 17, 2021 - The “drop” method is not as useful here, and instead, we are selecting data using the “loc” indexer and specifying the desired values in the column(s) we are using to select. There is a full blog post on Pandas DataFrame iloc and loc selection on this blog, but a basic example is here: # Check the initial shape of the DataFrame data.shape --> (238, 11) # Delete rows where case numbers are zero # This deletion is completed by "selecting" rows where case numbers are non zero data = data.loc[data["cases"] != 0] data.shape --> (223, 11) # Delete rows where there have been no cases in 24 hours AND no cases in 7 days # Note that you must put each condition within parenthesis data = data.loc[(data["deaths_7_days"] > 0) & (data["deaths_24_hours"] > 0)] data.shape --> (114, 11)
🌐
Real Python
realpython.com › how-to-drop-null-values-in-pandas
How to Drop Null Values in pandas With .dropna() – Real Python
June 19, 2025 - To clarify that you’re removing rows, you explicitly set axis to 0. However, you can omit this argument since 0 is the default value for the axis parameter. To restrict your analysis to the two columns you want, you pass the Python list ["discount", "sale_price"] as the subset parameter.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.dropna.html
pandas.DataFrame.dropna — pandas 3.0.1 documentation
Drop the rows where at least one element is missing. >>> df.dropna() name toy born 1 Batman Batmobile 1940-04-25 · Drop the columns where at least one element is missing.
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas drop rows based on column value
Pandas Drop Rows Based on Column Value - Spark By {Examples}
June 5, 2025 - Use drop() method to delete rows based on column value in pandas DataFrame, as part of the data cleansing, you would be required to drop rows from the
🌐
W3Schools
w3schools.com › python › pandas › pandas_cleaning_empty_cells.asp
Pandas - Cleaning Empty Cells
Note: Now, the dropna(inplace = True) will NOT return a new DataFrame, but it will remove all rows containing NULL values from the original DataFrame. Another way of dealing with empty cells is to insert a new value instead. This way you do not have to delete entire rows just because of some empty cells. The fillna() method allows us to replace empty cells with a value: ... The example above replaces all empty cells in the whole Data Frame. To only replace empty values for one column, specify the column name for the DataFrame:
🌐
CERN
root-forum.cern.ch › newbie
How to efficiently remove zero entries from DataFrame rows - Newbie - ROOT Forum
September 23, 2024 - Hi all, I have a dataframe with columns “pp” and “pt”. each row of these columns is a vector and some of the values are 0. I’m trying to find a way to efficiently remove the zeros. I’m using Jupyter Notebooks and Python. Example of the structure (where 1 stands for just one row of the dataframe): 1 | 5.40445f | | | 0.339785f | | | 0.0130158f | | | 0.00000f And I want it to be: 1 | 5.40445f | | | 0.339785f | | | 0.0130158f | Ultimately I just want a histog...
🌐
Saturn Cloud
saturncloud.io › blog › how-to-drop-rows-with-all-zeros-in-pandas-dataframe
How to Drop Rows with all Zeros in Pandas DataFrame | Saturn Cloud Blog
December 1, 2023 - Pandas is widely used in data science and machine learning for tasks such as data cleaning, data wrangling, and data visualization. To drop rows with all zeros in a Pandas DataFrame, we can use the drop() method along with the axis parameter. The ...