If you want to change the order of columns in the pandas data frame, you can do so by providing the desired order of columns as a list.
In below snipped, the original order of the columns is changed by selecting the columns in a new order.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# Defining Department Data import pandas as pd DepartmentData=pd.DataFrame({'Dep': ['BI','QA','DEV','DEV','QA'], 'id': [101,102,103,104,105], 'DOJ': ['12-Mar-2020','2-Feb-2020','15-Jan-2020','23-Apr-2019','14-Sep-2019'] }) # Priting data print(DepartmentData) # Changing the order of columns in data columnOrder=['id','DOJ','Dep'] DepartmentData=DepartmentData[columnOrder] # Priting data print(DepartmentData) |
Sample Output:

Author Details
Lead Data Scientist
Farukh is an innovator in solving industry problems using Artificial intelligence. His expertise is backed with 10 years of industry experience. Being a senior data scientist he is responsible for designing the AI/ML solution to provide maximum gains for the clients. As a thought leader, his focus is on solving the key business problems of the CPG Industry. He has worked across different domains like Telecom, Insurance, and Logistics. He has worked with global tech leaders including Infosys, IBM, and Persistent systems. His passion to teach inspired him to create this website!