Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

change order of headers pandas

In [6]: df
Out[6]:
          0         1         2         3         4      mean
0  0.445598  0.173835  0.343415  0.682252  0.582616  0.445543
1  0.881592  0.696942  0.702232  0.696724  0.373551  0.670208
2  0.662527  0.955193  0.131016  0.609548  0.804694  0.632596
3  0.260919  0.783467  0.593433  0.033426  0.512019  0.436653
4  0.131842  0.799367  0.182828  0.683330  0.019485  0.363371
5  0.498784  0.873495  0.383811  0.699289  0.480447  0.587165
6  0.388771  0.395757  0.745237  0.628406  0.784473  0.588529
7  0.147986  0.459451  0.310961  0.706435  0.100914  0.345149
8  0.394947  0.863494  0.585030  0.565944  0.356561  0.553195
9  0.689260  0.865243  0.136481  0.386582  0.730399  0.561593

In [7]: cols = df.columns.tolist()

In [8]: cols
  
Out[8]: [0L, 1L, 2L, 3L, 4L, 'mean']
         # Arrange the Cols
      	 cols = ['mean', 0L, 1L, 2L, 3L, 4L]
In [16]: df = df[cols]  #    OR    df = df.ix[:, cols]

In [17]: df
Out[17]:
       mean         0         1         2         3         4
0  0.445543  0.445598  0.173835  0.343415  0.682252  0.582616
1  0.670208  0.881592  0.696942  0.702232  0.696724  0.373551
2  0.632596  0.662527  0.955193  0.131016  0.609548  0.804694
3  0.436653  0.260919  0.783467  0.593433  0.033426  0.512019
4  0.363371  0.131842  0.799367  0.182828  0.683330  0.019485
5  0.587165  0.498784  0.873495  0.383811  0.699289  0.480447
6  0.588529  0.388771  0.395757  0.745237  0.628406  0.784473
7  0.345149  0.147986  0.459451  0.310961  0.706435  0.100914
8  0.553195  0.394947  0.863494  0.585030  0.565944  0.356561
9  0.561593  0.689260  0.865243  0.136481  0.386582  0.730399
Comment

PREVIOUS NEXT
Code Example
Python :: python read vcf file line by line 
Python :: types of methods in oop python 
Python :: check if any entries arte none 
Python :: scikit learn introduction 
Python :: what hormone causes the feeling of love 
Python :: python opening file modalities 
Python :: backticks equivalent python template 
Python :: how to find the medium, first, second and third quartile in a pandas data frame 
Python :: azure functions read only file system 
Python :: how to insert image in python 
Python :: python get pc runtime 
Python :: getting over it 
Python :: List Get a Element-2 
Python :: python lvl up 
Python :: pe039 
Python :: bulk m4a to wav ffmepeg 
Python :: print out python 
Python :: how to run matrix in python 
Python :: pinyin to pinyin numbers python 
Python :: flash not defined python flask 
Python :: create matrix with complex python 
Python :: def identity_block(X, f, filters, training=True, initializer=random_uniform): 
Python :: var person 
Python :: python code to save data with multiple sheet in excel 
Python :: pyglet on close 
Python :: starter is a naive datetime. Use pytz to make it a "US/Pacific" datetime instead and assign this converted datetime to the variable local. 
Python :: how to get the remainder of a number when dividing in python 
Python :: createdb psql 
Python :: python zip function 
Python :: telephone number word generator python 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =