我有一个 pandas DataFrame df_ref
,它类似于:
a b c result
0 (-0.001, 0.00482] (-0.001, 1.0] (-0.001, 1.0] 0.622745
1 (-0.001, 0.00482] (-0.001, 1.0] (-0.001, 1.0] 0.450869
2 (-0.001, 0.00482] (-0.001, 1.0] (1.0, 5.0] 0.693840
3 (-0.001, 0.00482] (-0.001, 1.0] (1.0, 5.0] 0.484881
4 (-0.001, 0.00482] (-0.001, 1.0] (5.0, 13.0] 0.687814
... ... ... ... ... ... ...
91 (17.953, 90.0] (4.0, 480.0] (1.0, 5.0] 0.500905
92 (17.953, 90.0] (4.0, 480.0] (5.0, 13.0] 0.500905
93 (17.953, 90.0] (4.0, 480.0] (5.0, 13.0] 0.500905
94 (17.953, 90.0] (4.0, 480.0] (13.0, 1103.0] 0.500905
95 (17.953, 90.0] (4.0, 480.0] (13.0, 1103.0] 0.500905
和另一个 DataFrame 称为df
:
a b c
1 0.004213 11.0 11.0
2 32.326794 0.0 0.0
3 5.415845 1.0 1.0
4 0.001968 10.0 41.0
5 0.014745 9.0 13.0
... ... ... ... ... ...
1435435 0.000185 1.0 1.0
1435436 89.999919 0.0 0.0
1435437 4.788090 1.0 1.0
1435438 7.441620 0.0 22.0
1435439 0.001053 1.0 1.0
我希望将 的每一行df
与 的所有行进行比较df_ref
并确定它们属于哪一行,然后从中提取相应的result
值df_ref
并将这些值放入具有 1,435,439 个元素的列表中(或者只是 中的一个新列df
,两者都有效)。由于数据很大,因此需要对其进行有效编码,因此我知道简单的循环可能不是最好的方法,这就是我寻求帮助的原因。