I have a Pandas Dataframe that get generated every day and the list of columns present in the Dataframe can vary when it gets generated each time.
I am trying to see if I can sort the sequence in which the columns are stored as the final output of the Dataframe in a specific format. If new columns are present they are placed towards the end.
Given below is how I am trying to build this final output
expected_columns = ['cust_id','cost_id','sale_id','prod_id']
Sample Dataframe columns:
['customer_name','cust_id','sale_id','sale_time']
I would like the above Dataframe structured as below:
['cust_id','sale_id','customer_name','sale_time']
Basically the columns in expected_columns takes the first priority and then place the other columns in the Dataframe as successive column of the new Dataframe.