How to change the order of DataFrame columns in pandas?

0 votes

Hi Guys,

I have a Pandas Dataframe. I want to change the order of DataFrame columns. How can I do that?

Oct 20 in Python by akhtar
• 32,960 points
34 views

1 answer to this question.

0 votes

Hi@akhtar,

You can rearrange a DataFrame object by declaring a list of columns and using it as a key. You can see the below example for a better understanding.

import pandas as pd 
fruit = pd.DataFrame(data = {'Fruit':['apple', 'banana', 'blueberry', 'grape'], 'Color':['red', 'yellow', 'blue', 'purple'], 'Seeds':['yes', 'no', 'yes', 'no']}) 
fruit.set_index('Fruit', inplace = True) 
answered Oct 20 by MD
• 77,580 points

Related Questions In Python

0 votes
1 answer

How to find the sum of rows in Pandas dataframe?

You can use a combination groupby function with the sum() method. ...READ MORE

answered May 9, 2019 in Python by Jisha
2,381 views
0 votes
1 answer

How to print all the index of Pandas Dataframe?

Try this: print(df.index.values) READ MORE

answered Apr 8, 2019 in Python by Yogi
338 views
0 votes
1 answer

How to find the index of a particular value in a dataframe?

First, use the dataframe to match the ...READ MORE

answered Apr 8, 2019 in Python by Esha
56,348 views
0 votes
0 answers

how do sort the columns in a dataframe using the pandas?

can you give an example using dataframe? READ MORE

May 6, 2019 in Python by Waseem
• 4,540 points
95 views
0 votes
1 answer
0 votes
1 answer

How to create Pandas series from dictionary?

Here's a sample script: import pandas as pd import ...READ MORE

answered Apr 1, 2019 in Python by Prateek
518 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,557 views
+1 vote
2 answers

How to change/update cell value in Python Pandas dataframe?

You can use the at() method to ...READ MORE

answered Apr 8, 2019 in Python by Kunal
88,534 views
0 votes
1 answer

How to change data types in Pandas DataFrame?

Hi@akhtar, You can use astype function to change ...READ MORE

answered Jun 22 in Python by MD
• 77,580 points
166 views