{"id":7329,"date":"2025-03-19T04:32:20","date_gmt":"2025-03-19T04:32:20","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=7329"},"modified":"2025-03-19T05:49:31","modified_gmt":"2025-03-19T05:49:31","slug":"how-to-change-order-of-dataframe-columns-in-python","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/","title":{"rendered":"How to Change Order of Dataframe Columns in Python"},"content":{"rendered":"\n<p>Python dataframes provide a great way to store data in a tabular manner. They support tons of functions to easily analyze and manipulate data, making it easy for developers to work with them. Many times, Python developers need to change the order of columns in Python dataframe. There are several simple ways to do this. In this article, we will learn how to change order of dataframe columns in Python.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/#How_to_Change_Order_of_Dataframe_Columns_in_Python\" >How to Change Order of Dataframe Columns in Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/#1_Using_Column_List\" >1. Using Column List<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/#2_Using_loc\" >2. Using loc<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/#3_Using_iloc\" >3. Using iloc<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/#4_Using_insert\" >4. Using insert<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/#5_Using_reindex\" >5. Using reindex<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/#6_Using_reverse\" >6. Using reverse<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Change_Order_of_Dataframe_Columns_in_Python\"><\/span>How to Change Order of Dataframe Columns in Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are the different ways to change the order of columns in Python dataframe. Let us say you have the following dataframe.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import pandas as pd<br><br>data = {'id': [1, 2, 3, 4], <br>        'name': ['Jim','Jane','John', 'Tim'], <br>        'marks': [45, 85, 69, 75]}<br>df = pd.DataFrame(data)<br>print(df)<br><br>## output<br><br>   id  name  marks<br>0   1   Jim     45<br>1   2  Jane     85<br>2   3  John     69<br>3   4   Tim     75<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Using_Column_List\"><\/span>1. Using Column List<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This is one of the simplest ways to alter column order for dataframes. You can pass a list of columns with new order to the dataframe variable as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">df = df[list_with_new_column_order]<\/pre>\n\n\n\n<p>Here is an example to interchange the columns name and marks so that the new order of dataframe columns is id, marks, name. We pass a list containing new column order.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">df=df[['id','marks','name']]<br>print(df)<br><br>## output<br><br>   id  marks  name<br>0   1     45   Jim<br>1   2     85  Jane<br>2   3     69  John<br>3   4     75   Tim<\/pre>\n\n\n\n<p>If you have too many columns in your dataframe, or you do not remember the names of all columns, then it can be tedious to list names of all the columns. In such cases, if you want to change the position of just one or a few columns, you can use a list comprehension in addition to the column names. Here is an example to make marks column as the first column and leave the order of rest of the columns unchanged.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">df=df[['marks'] + [ col for col in df.columns if col != 'marks' ]]<br>print(df)<br><br>## output<br><br>   marks  id  name<br>0     45   1   Jim<br>1     85   2  Jane<br>2     69   3  John<br>3     75   4   Tim<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Using_loc\"><\/span>2. Using loc<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Every dataframe supports loc method that allows you to re-order the columns as per your requirement. It allows you to re-order columns by directly specifying their names. It is generally used to extract select rows and columns from a given dataframe. But it can also be used to re-order columns. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dataframe.loc[start_row:end_row,start_column:end_column]<br>OR<br>dataframe.loc[start_row:end_row,list_of_column_names]<\/pre>\n\n\n\n<p>Here is an example to re-arrange dataframe columns using loc method.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">df=df.loc[:,['id','marks','name']]<br>print(df)<br><br>## output<br><br>   id  marks  name<br>0   1     45   Jim<br>1   2     85  Jane<br>2   3     69  John<br>3   4     75   Tim<\/pre>\n\n\n\n<p>Although this method appears similar to the previous one, it has an important difference. When you use loc() function, it returns a view or slice of the original dataframe. It does not create a copy of the original dataframe. In other words, the dataframe with new column order will reference the same memory space as the original dataframe. In the previous solution, it will create a copy of the original dataframe. Since we re-assign it back to the original dataframe, it will overwrite the original dataframe. Otherwise, the result would have been a copy of the original.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Using_iloc\"><\/span>3. Using iloc<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Every dataframe also supports iloc method that allows you to select data based on column index instead of column names. This is great if you want to change the columns using their positions instead of their names. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dataframe.iloc[start_row:end_row,start_column_index:end_column_index]<br>OR<br>dataframe.iloc[start_row:end_row,list_of_column_indexes]<\/pre>\n\n\n\n<p>Here is an example to re-arrange columns using their indexes.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">df=df.iloc[:,[0,2,1]]<br>print(df)<br><br>## output <br><br>   id  marks  name<br>0   1     45   Jim<br>1   2     85  Jane<br>2   3     69  John<br>3   4     75   Tim<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Using_insert\"><\/span>4. Using insert<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this approach, we extract the required column using pop() function and insert it back into dataframe, at the desired position, using insert() function. Here is the syntax of insert() function.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dataframe.insert(location, column_name, column_value, allow_duplicates = False) <\/pre>\n\n\n\n<p>In the above command, we first specify the location of the column to be inserted. This is followed by column name, followed by column values. The last argument allow_duplicates is optional.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">col = df.pop(\"marks\")<br>df.insert(0, col.name, col)<br>print(df)<br><br>## output<br><br>   marks  id  name<br>0     45   1   Jim<br>1     85   2  Jane<br>2     69   3  John<br>3     75   4   Tim<\/pre>\n\n\n\n<p>In the above code, pop() function extracts the column marks, both column name as well as values, and stores it in col variable. Now the dataframe contains only 2 columns. We use insert function to insert the marks column back into dataframe df at 1st column position. This is followed by the value of marks column.<\/p>\n\n\n\n<p>This method is useful if you want to change position of just one column in a dataframe with many columns, without listing names or indexes of all columns.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_Using_reindex\"><\/span>5. Using reindex<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can also call reindex method on a dataframe to re-order its columns. You just need to pass columns argument, that contains a list of column names in the new order. Here is an example to re-order dataframe columns as id, marks, name.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">df=df.reindex(columns=['id','marks','name'])<br>print(df)<br><br>## output<br><br>   id  marks  name<br>0   1     45   Jim<br>1   2     85  Jane<br>2   3     69  John<br>3   4     75   Tim<\/pre>\n\n\n\n<p>You can also call Python list functions on the list of column names. Here is an example to re-order dataframe columns such that their column names are in alphabetical order.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">df=df.reindex(columns=sorted(['id','marks','name']))<br>print(df)<\/pre>\n\n\n\n<p>You can also use list comprehensions. Here is an example to set name column as first column, followed by the rest of columns.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">df=df.reindex(columns=(['name'] + list([a for a in df.columns if a != 'name'])))<br>print(df)<br><br>## output <br><br>   name  id  marks<br>0   Jim   1     45<br>1  Jane   2     85<br>2  John   3     69<br>3   Tim   4     75<\/pre>\n\n\n\n<p>Please note, you can also use copy=True argument if you want the result to be stored as a separate copy. Else you can set it to False or omit it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"6_Using_reverse\"><\/span>6. Using reverse<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Sometimes, you may want to reverse the order of columns. This is very tedious if you need to manually list the reverse order of columns, and if there are many columns. In such cases, you can call reverse() function on the list of columns. It will automatically return a list of reverse order of columns.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cols = list(df.columns)<br>cols.reverse()<br>df=df[cols]<br>print(df)<br><br>## output<br><br>   marks  name  id<br>0     45   Jim   1<br>1     85  Jane   2<br>2     69  John   3<br>3     75   Tim   4<\/pre>\n\n\n\n<p>In the above code, we first get the list of column names using df.columns and list() function. Then we call reverse function on this to reverse the order of columns. Then we pass the list with new order of columns to df[&#8230;]. This will reverse the order of dataframe columns.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we have learnt several ways to change order of columns in Pandas dataframe in Python. The most basic way is to provide a list of column names in new order. This method will create a separate copy for the result. You can also use loc or iloc function for this purpose. In this case, it will create a view or slice of original dataframe. These are useful for re-ordering <a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-select-multiple-columns-in-pandas-dataframe\/\">multiple columns of your dataframe<\/a>. If you want to move just one column, then you can use insert function. If you want to reverse order of all columns in dataframe, then you can use reverse function. Having said that, you can use any of these methods as per your requirement.<\/p>\n\n\n\n<p>Also read:<\/p>\n\n\n\n<p><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-select-multiple-columns-in-pandas-dataframe\/\">How to Select Multiple Columns in Pandas DataFrame<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/\">How to Randomly Select Item from Python List<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-detect-invalid-date-in-javascript\/\">How to Detect Invalid Date in JavaScript<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes Python developers need to alter column order of Pandas dataframe. Here is how to change order of dataframe columns in Python.<\/p>\n","protected":false},"author":1,"featured_media":7365,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[301],"tags":[398],"class_list":["post-7329","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-column-order"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Change Order of Dataframe Columns in Python - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Sometimes Python developers need to alter column order of Pandas dataframe. Here is how to change order of dataframe columns in Python.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Change Order of Dataframe Columns in Python - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Sometimes Python developers need to alter column order of Pandas dataframe. Here is how to change order of dataframe columns in Python.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Ubiq BI\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ubiqbi\" \/>\n<meta property=\"article:published_time\" content=\"2025-03-19T04:32:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-03-19T05:49:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/change-column-order-python-dataframe.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"269\" \/>\n\t<meta property=\"og:image:height\" content=\"202\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sreeram Sreenivasan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:site\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sreeram Sreenivasan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-change-order-of-dataframe-columns-in-python\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-change-order-of-dataframe-columns-in-python\\\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Change Order of Dataframe Columns in Python\",\"datePublished\":\"2025-03-19T04:32:20+00:00\",\"dateModified\":\"2025-03-19T05:49:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-change-order-of-dataframe-columns-in-python\\\/\"},\"wordCount\":1006,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-change-order-of-dataframe-columns-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/change-column-order-python-dataframe.jpg?fit=269%2C202&ssl=1\",\"keywords\":[\"column order\"],\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-change-order-of-dataframe-columns-in-python\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-change-order-of-dataframe-columns-in-python\\\/\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-change-order-of-dataframe-columns-in-python\\\/\",\"name\":\"How to Change Order of Dataframe Columns in Python - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-change-order-of-dataframe-columns-in-python\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-change-order-of-dataframe-columns-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/change-column-order-python-dataframe.jpg?fit=269%2C202&ssl=1\",\"datePublished\":\"2025-03-19T04:32:20+00:00\",\"dateModified\":\"2025-03-19T05:49:31+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Sometimes Python developers need to alter column order of Pandas dataframe. Here is how to change order of dataframe columns in Python.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-change-order-of-dataframe-columns-in-python\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-change-order-of-dataframe-columns-in-python\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-change-order-of-dataframe-columns-in-python\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/change-column-order-python-dataframe.jpg?fit=269%2C202&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/change-column-order-python-dataframe.jpg?fit=269%2C202&ssl=1\",\"width\":269,\"height\":202,\"caption\":\"How to Change Order of Dataframe Columns in Python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-change-order-of-dataframe-columns-in-python\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Change Order of Dataframe Columns in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\",\"name\":\"Ubiq BI\",\"description\":\"Build dashboards &amp; reports in minutes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\",\"name\":\"Sreeram Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"caption\":\"Sreeram Sreenivasan\"},\"description\":\"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/sreeram-sreenivasan\\\/\"],\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/author\\\/wordpress\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Change Order of Dataframe Columns in Python - Ubiq BI","description":"Sometimes Python developers need to alter column order of Pandas dataframe. Here is how to change order of dataframe columns in Python.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/","og_locale":"en_US","og_type":"article","og_title":"How to Change Order of Dataframe Columns in Python - Ubiq BI","og_description":"Sometimes Python developers need to alter column order of Pandas dataframe. Here is how to change order of dataframe columns in Python.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2025-03-19T04:32:20+00:00","article_modified_time":"2025-03-19T05:49:31+00:00","og_image":[{"width":269,"height":202,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/change-column-order-python-dataframe.jpg","type":"image\/jpeg"}],"author":"Sreeram Sreenivasan","twitter_card":"summary_large_image","twitter_creator":"@UbiqBI","twitter_site":"@UbiqBI","twitter_misc":{"Written by":"Sreeram Sreenivasan","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Change Order of Dataframe Columns in Python","datePublished":"2025-03-19T04:32:20+00:00","dateModified":"2025-03-19T05:49:31+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/"},"wordCount":1006,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/change-column-order-python-dataframe.jpg?fit=269%2C202&ssl=1","keywords":["column order"],"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/","name":"How to Change Order of Dataframe Columns in Python - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/change-column-order-python-dataframe.jpg?fit=269%2C202&ssl=1","datePublished":"2025-03-19T04:32:20+00:00","dateModified":"2025-03-19T05:49:31+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Sometimes Python developers need to alter column order of Pandas dataframe. Here is how to change order of dataframe columns in Python.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/change-column-order-python-dataframe.jpg?fit=269%2C202&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/change-column-order-python-dataframe.jpg?fit=269%2C202&ssl=1","width":269,"height":202,"caption":"How to Change Order of Dataframe Columns in Python"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-change-order-of-dataframe-columns-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Change Order of Dataframe Columns in Python"}]},{"@type":"WebSite","@id":"https:\/\/ubiq.co\/tech-blog\/#website","url":"https:\/\/ubiq.co\/tech-blog\/","name":"Ubiq BI","description":"Build dashboards &amp; reports in minutes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc","name":"Sreeram Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","caption":"Sreeram Sreenivasan"},"description":"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.","sameAs":["https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/"],"url":"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/change-column-order-python-dataframe.jpg?fit=269%2C202&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-1Ud","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7329","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/comments?post=7329"}],"version-history":[{"count":40,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7329\/revisions"}],"predecessor-version":[{"id":7376,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7329\/revisions\/7376"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/7365"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=7329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=7329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=7329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}