How to specify the columns of Data frame in python?

ipython

#1

I have a data in which state,year and pop are the columns when I have created the data frame the columns are arranged in sorted order .

 data = {'state': ['Ohio', 'Ohio', 'Ohio', 'Nevada', 'Nevada'],
               'year': [2000, 2001, 2002, 2001, 2002],
                'pop': [1.5, 1.7, 3.6, 2.4, 2.9]}

frame = DataFrame(data)

In [38]: frame
Out[38]:
pop state year
0 1.5 Ohio 2000
1 1.7 Ohio 2001
2 3.6 Ohio 2002
3 2.4 Nevada 2001
4 2.9 Nevada 2002

Here according to alphabet the first column is pop .I want that my first column should be year ,second column is pop and last one is state.


#2

Hi @sid100158

Try to explicitly define the orders of the columns in data frame.

frame = frame[['state','year','pop']]

Regards
Anikit Gupta