0

I have three Dataframes : df1, df2, df3 with the same number of "rows" but different number of "columns" and different "column" labels. I want to "merge" them in one single dataframe with the order df1,df2,df3 and keeping the original column labels.

I've read in Combine a list of pandas dataframes to one pandas dataframe that this can be done by:

df = pd.DataFrame.from_dict(map(dict,df_list))

But I cannot fully understand the code. I assume df_list is:

df_list = [df1,df2,df3]

But what is dict? A dictionary of df_list? How to get it?

jpcgandre
  • 1,487
  • 5
  • 31
  • 55
  • I think in this case `dict` refers to the dict method in the python built-ins. It's mapped to df_list. – tobsecret Jul 16 '18 at 22:38
  • This solution doesn't work for me on Python 3.6.5 / Pandas v0.23.0. It errors with `TypeError: data argument can't be an iterator`. Converting to `list` first (to mimic Python 2.7) comes up with unexpected results too. I think the version differences are insurmountable here, look for a more recent question. – jpp Jul 16 '18 at 23:02

1 Answers1

0

I solve this by:

        df = pd.concat([df1, df2], axis=1, sort=False)
        df = pd.concat([df, df3], axis=1, sort=False)
jpcgandre
  • 1,487
  • 5
  • 31
  • 55