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

Pandas rearrange the order of only two columns

  • Python
  • Pandas, Python

When you have a table with many columns but only want to rearrange or swap two or a few columns.

cols = list(df.columns)
a, b = cols.index('XXXX'), cols.index('YYYY')
cols[b], cols[a] = cols[a], cols[b]
df = df[cols]

Source:
https://stackoverflow.com/questions/53141240/pandas-how-to-swap-or-reorder-columns

Post navigation

← Previous Post Python pickle save/load dictionary into a file
Next Post → Python dictionary use value to get key
Copyright 2024 | by bioinfocore