一次使用两个不同的数据框

Use two different Data frame at once

我有两个不同的数据集,想比较数据集如下; 我必须同时比较相同的 x 和 y,并且在同一个数据帧中有 x 和 y

date
    time                   x              
0   1648598400000         233                   
0   1648598400000         234
1   1648598403000         553
2   1648598404000         987
3   1648598405000         732
4   1648598406000         234
5   1648598406000         465

    time                   y
0   1648598400000         6758
1   1648598403000         8678
2   1648598404000         8778
3   1648598405000         4535
4   1648598406000         7656
5   1648598406000         8977

你在找merge:

>>> df1.merge(df2, on='time', how='outer')

            time    x     y
0  1648598400000  233  6758
1  1648598400000  234  6758
2  1648598403000  553  8678
3  1648598404000  987  8778
4  1648598405000  732  4535
5  1648598406000  234  7656
6  1648598406000  234  8977
7  1648598406000  465  7656
8  1648598406000  465  8977

我使用的设置:

>>> df1
            time    x
0  1648598400000  233
0  1648598400000  234
1  1648598403000  553
2  1648598404000  987
3  1648598405000  732
4  1648598406000  234
5  1648598406000  465

>>> df2
            time     y
0  1648598400000  6758
1  1648598403000  8678
2  1648598404000  8778
3  1648598405000  4535
4  1648598406000  7656
5  1648598406000  8977