小编LOR*_*R13的帖子

使用模式在两个数据帧之间交换行

我有 2 个数据框,如下所示:

在每个数据帧中,值列中都有 1-2 的模式。(这些值对我的问题并不重要,只是为了演示模式)

df1 = {'idx': [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
       'values': [20, 1000, 10001, 21, 1000, 1002, 22, 1003, 1007,23]}
df2 = {'idx': [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
       'values': [1000, 21, 22, 1000, 22, 23, 1000, 20, 21, 1000]}
Run Code Online (Sandbox Code Playgroud)

我需要在两个数据帧之间交换行,以便结果是:

df_expected1 = {'idx': [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
       'values': [20, 21, 22, 21, 22, 23, 22, 20, 21,23]} …
Run Code Online (Sandbox Code Playgroud)

python swap pandas

1
推荐指数
1
解决办法
63
查看次数

标签 统计

pandas ×1

python ×1

swap ×1