0

I have two data-frames

df1

Index([u'CASE_NO', u'DECISION_DATE', u'CASE_STATUS', u'APPLICATION_TYPE', u'EMPLOYER_NAME', u'EMPLOYER_ADDRESS_1', u'EMPLOYER_ADDRESS_2', u'EMPLOYER_CITY', u'EMPLOYER_STATE', u'EMPLOYER_POSTAL_CODE', u'2007_NAICS_US_CODE', u'2007_NAICS_US_TITLE', u'US_ECONOMIC_SECTOR', u'PW_SOC_CODE', u'PW_SOC_TITLE', u'PW_JOB_TITLE_9089', u'PW_LEVEL_9089', u'PW_SOURCE_NAME_9089', u'PW_AMOUNT_9089', u'PW_UNIT_OF_PAY_9089', u'WAGE_OFFER_FROM_9089', u'WAGE_OFFER_TO_9089', u'WAGE_OFFER_UNIT_OF_PAY_9089', u'JOB_INFO_WORK_CITY', u'JOB_INFO_WORK_STATE', u'COUNTRY_OF_CITZENSHIP', u'CLASS_OF_ADMISSION'], dtype='object')

df2

Index([u'CASE_NO', u'DECISION_DATE', u'CASE_STATUS', u'APPLICATION_TYPE', u'EMPLOYER_NAME', u'EMPLOYER_ADDRESS_1', u'EMPLOYER_CITY', u'EMPLOYER_STATE', u'EMPLOYER_POSTAL_CODE', u'2007_NAICS_US_CODE', u'2007_NAICS_US_TITLE', u'US_ECONOMIC_SECTOR', u'PW_SOC_CODE', u'PW_SOC_TITLE', u'PW_JOB_TITLE_9089', u'PW_LEVEL_9089', u'PW_SOURCE_NAME_9089', u'PW_AMOUNT_9089', u'PW_UNIT_OF_PAY_9089', u'WAGE_OFFER_FROM_9089', u'WAGE_OFFER_TO_9089', u'WAGE_OFFER_UNIT_OF_PAY_9089', u'JOB_INFO_WORK_CITY', u'JOB_INFO_WORK_STATE', u'COUNTRY_OF_CITZENSHIP', u'CLASS_OF_ADMISSION'], dtype='object')

I am trying to concat the two dataframes but the columns are not in the same order in both the dataframes. I came across this question How to change the order of DataFrame columns?

and I think I am thinking if there is something else to do more efficiently.

df2 columns should be reordered to match the df1 columns.

1 Answer 1

2

If the column names are the same but just in a different order, you can do df2[df1.columns].

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.