Skip to content
  • View menu
  • View sidebar

bioinfo core

Index & solution of bioInfo utilities

  • Home
  • All entries
  • Blogs
  • Contact
  • About

Categories

  • Between languages (7)
  • Blogs (8)
  • Python (35)
  • R (1)
  • Unix (37)

Tags

bedfile Blogs conda Excel html numpy Pandas Python R slurm Unix
04/01/202010/21/2021 by bioinfocore

Pandas remove rows with all zeros

  • Python
  • Pandas, Python

For Pandas dataframes, remove rows with all 0s, also applies to remove other values.

Below lines all work.

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

Source: https://stackoverflow.com/questions/22649693/drop-rows-with-all-zeros-in-pandas-data-frame

Post navigation

← Previous Post Split bed file by chromosome
Next Post → Pandas apply function to values in a DataFrame
Copyright 2022 | by bioinfocore