0

I'm trying to create a Pandas dataframe that is created of multiple smaller dataframes. All dataframes got the same Index variable but sometimes have different coloums, wich should be added if non existent.

So basically a join (outer i guess) would be the right thing. But instead of creating a new column in case of an overlap it should be pushed in the column with the original name.

To give a small example:

A:                       B:                     C:
Time   col1   col2       Time   col1  col2       Time   col3   col4
0      1      2          0.2    2     1          0.1    1      5
0.1    3      4          0.3    1     2          0.2    7      4 

Should be combined to:

Time col1 col2 col3 col4
0    1    2    1    5
0.1  3    4    7    4
0.2  2    1    NaN  NaN
0.3  1    2    NaN  NaN

I searched for an elegant solution to this but all i came up with is iterating over every cell of the dataframe. Is there any better possibility?

manni
  • 5
  • 1
  • 5

1 Answers1

0
pd.concat([A,B,C])

does this work for you?

  • Thanks for this. Totaly not had concat in mind.. In addition to this answer i needed to do a `df.groupby(df.index).mean()` to remove multiple rows with same Index. – manni Jan 14 '20 at 14:04