Concatenate specific columns in pandas

  pandas, python

Im trying to concatenate 4 different datasets onto pandas python. I can concatenated them but it results in several of the same column names. How do I only produce only one column of the same name, then multiples?

concatenated_dataframes = pd.concat(
    [
        dice.reset_index(drop=True),
        json.reset_index(drop=True),
        flexjobs.reset_index(drop=True),
        indeed.reset_index(drop=True),
        simply.reset_index(drop=True),
    ],
    axis=1,
    ignore_index=True,
)
concatenated_dataframes_columns = [
    list(dice.columns),
    list(json.columns),
    list(flexjobs.columns),
    list (indeed.columns),
    list(simply.columns)
]
    
flatten = lambda nested_lists: [item for sublist in nested_lists for item in sublist]

concatenated_dataframes.columns = flatten(concatenated_dataframes_columns)
df= concatenated_dataframes

This results in 
UNNAMED: 0  TITLE   COMPANY     DESCRIPTION     LOCATION    TITLE   JOBLOCATION     POSTEDDATE  DETAILSPAGEURL  COMPANYPAGEURL  COMPANYLOGOURL  SALARY  CLIENTBRANDID   COMPANYNAME     EMPLOYMENTTYPE  SUMMARY     SCORE   EASYAPPLY   EMPLOYERTYPE    WORKFROMHOMEAVAILABILITY    ISREMOTE    UNNAMED: 0  TITLE   SALARY  JOBTYPE     LOCATION    DESCRIPTION     UNNAMED: 0  TITLE   SALARY  JOBTYPE     DESCRIPTION     LOCATION    UNNAMED: 0  COMPANY     DESCRIPTION     LOCATION    SALARY  TITLE

Again, how do i combined all the ‘titles’ in one column, all the ‘location’ in one column, and so on? Instead of have multiple of them.

Source: Python Questions

LEAVE A COMMENT