简体   繁体   中英

join columns into one single dataframe using one line of pandas command

I have 33 single columns, each works as a dataframe:

col1_df, col2_df, col3_df....col33_df

How do I join them together into one single dataframe?

my code is

df = [col1_df, col2_df....col33_df], but the return is not a dataframe

Is there one pandas line to solve this?

flat the origin df to a list, and concat or merge the col_df

col_df_list = df.values.flatten()
dfn = pd.concat(col_df_list)

Try using pd.concat :

df = pd.concat([col1_df, col2_df, col3_df....col33_df], axis=1)

And now:

print(df)

Would give the desired output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM