【发布时间】:2020-03-28 01:23:12
【问题描述】:
我有 16 个具有相同行数/列数的不同数据帧和另外 2 个具有相同形状的单独数据帧,我用来与 16 个数据帧值进行比较。
我需要同时遍历所有数据帧,并将所有行值与单独的数据帧进行比较,然后创建另一个数据帧,结果如下:
比较:sum(row_values_of_dataframe) - sum(row_values_of_reference)。在下面的示例中,单元格df_a_ref_a 等于 (1 + 2 + 3 + 4) - (5 + 5 + 5 + 5) = -10
Dataframe A (df_a)
col1 | col 2 | col 3 | col 4
1 2 3 4
2 4 6 8
[...]
Dataframe B (df_b)
col1 | col 2 | col 3 | col 4
10 5 2 1
4 4 6 2
[...]
Reference Dataframe 1 (ref_1)
col1 | col 2 | col 3 | col 4
5 5 5 5
5 5 5 5
[...]
Reference Dataframe 2 (ref_2)
col1 | col 2 | col 3 | col 4
3 3 3 3
3 3 3 3
[...]
最终的数据框应该是:
df_a_ref_1 | df_a_ref_2 | df_b_ref_1 | df_b_ref_2 | ....
-10 -2 -2 6 ....
0 8 -4 4
[...]
此行为类似于 python 中的zip() 函数。
提前致谢,
【问题讨论】:
-
你熟悉矢量化吗?比迭代快很多,看起来很适合这类问题