python - 如何将 Pandas 查找表应用于 numpy 数组?

标签 python python-3.x pandas numpy dictionary

我有一个像这样的 Pandas 系列:

      measure
0    0.3
6    0.6
9    0.2
11   0.3
14   0.0
17   0.1
23   0.9

和一个像这样的 numpy 数组:

array([[ 0,  0,  9, 11],
       [ 6, 14,  6, 17]])

我如何从 numpy 数组中的值到系列中的索引进行查找以获取此信息:

array([[ 0.3,  0.3,  0.2, 0.3],
       [ 0.6,  0.0,  0.6, 0.1]])

最佳答案

通过 np.vectorize,使用系列 s 和数组 a:

np.vectorize(s.get)(a)

关于python - 如何将 Pandas 查找表应用于 numpy 数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48554344/

相关文章:

python - 提取一些 SIP header

python - UnitTest Python 仅模拟一个函数多次调用

python - 在python中根据终端宽度制表?

python - 如何从一系列 2D 图像创建 3D 模型?使用Python

python - Pandas - 如果字段为 NaT (Null),则用其他列填充

python - 在 Windows 中安装 Python-saml 包时出错

python-3.x - Yum 因键盘中断错误而崩溃

python - Pandas 数据帧 : merge files by common columns

python - 根据其他列的唯一组合更改数据框列值

Python Pandas 矩阵乘法 多项运算合二为一