Home>

There are 2 dataframes. something like this:

id feature_1
1 123
2 124
3 125
4 126
5 127
6 128
7 129
8 130
id feature_1
1 123
2 124
3 125
4 126
5 321
6 322
7 323
8 324

We need to combine them by id so that if id matches but feature_1 does not match, a line with the same id but a different feature_1 value is added. This is the result you should get

id feature_1
1 123
2 124
3 125
4 126
5 321
5 127
6 322
6 128
7 323
7 323
8 324
8 324

It is not necessary that the table be sorted by id, the main thing is that the resulting table should contain all the values ​​of feature_1. Triedpd.merge, but it turned out to create a table with a new feature_1_y column, where the values ​​​​that I needed were.

  • Answer # 1

    Try this:

    res= df1.append(df2).drop_duplicates()
    

    result:

    In[48]: res
    Out[48]:
       id feature_1
    0 1 123
    1 2 124
    2 3 125
    3 4 126
    4 5 127
    5 6 128
    6 7 129
    7 8 130
    4 5 321
    5 6 322
    6 7 323
    7 8 324