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/15/202010/21/2021 by bioinfocore

Pandas filter a dataframe by the sum of rows or columns

  • Python
  • Pandas, Python

Filter a dataframe by the sum of rows:

df = df[df.sum(axis=1) > 0]
df = df.loc[df.sum(axis=1) > 0,:]

Filter by sum of columns:

df = df.loc[:,df.sum() > 0]
df = df.loc[:,df.sum(axis=0) > 0]

Source:
https://stackoverflow.com/questions/40425484/filter-dataframe-in-pandas-on-sum-of-rows

Post navigation

← Previous Post Pandas remove rows or columns with null/nan/missing values
Next Post → Pickle UnicodeDecodeError incompatible between python2 and python3
Copyright 2024 | by bioinfocore