How to change the order of DataFrame columns in pandas

+1 vote

Hi Guys,

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

Oct 20, 2020 in Python by akhtar
• 38,260 points
890 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, 2020 by MD
• 95,460 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
4,644 views
0 votes
1 answer

How to combine two columns of text in pandas dataframe?

If both columns are strings, you can ...READ MORE

answered Jan 5, 2021 in Python by Gitika
• 65,770 points
1,989 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
5,466 views
+1 vote
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
282,051 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
2,345 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,486 views
+1 vote
3 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
147,506 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 23, 2020 in Python by MD
• 95,460 points
1,193 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP