小编cnc*_*gvg的帖子

熊猫,如何将列添加到多索引列DataFrame

这是我原始的DataFrame(带有multiindex列):

In [72]:df
Out[72]: 
          a                   b          
          x         y         x         y
0  1.545293 -0.459270  0.899254 -1.010453
1  0.458760  0.275400 -0.190951  0.169195
2 -0.941817  1.109823  0.077953 -0.247074
3  1.790101 -1.643470  0.979625 -1.704657
4 -2.044814 -0.243726 -0.039724  0.600066
Run Code Online (Sandbox Code Playgroud)

我还有另一个DataFrame:

In [77]:df2
Out[77]: 
          x         y
0 -1.085869 -0.952949
1  0.601585  0.570050
2  0.328601  0.802610
3 -0.415952 -0.090088
4  0.757545 -0.736933
Run Code Online (Sandbox Code Playgroud)

我该如何添加df2的列df以获取像这样的新DataFrame:

In [83]:df3
Out[83]: 
          a                   b                   c          
          x         y         x         y         x         y
0  1.545293 -0.459270  0.899254 -1.010453 -1.085869 -0.952949 …
Run Code Online (Sandbox Code Playgroud)

python pandas

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

pybind11:通过值/引用将 numpy 数组传递给 c++

这是我的函数签名

auto fun(py::array_t<double, py::array::c_style | py::array::forcecast> x)
Run Code Online (Sandbox Code Playgroud)

问题是,当传递 array of 时np.float64,该数组不会被复制并且可以修改fun(这不是预期的),当传递 array ofnp.float32或其他数据类型时,它会被复制。

我的问题是,有没有办法强制复制,x即使它的 dtype 是np.float64.

python numpy pybind11

5
推荐指数
0
解决办法
872
查看次数

标签 统计

python ×2

numpy ×1

pandas ×1

pybind11 ×1