我是Pandas的新手,所以请容忍我;我有一个数据帧A:
one two three
0 1 5 9
1 2 6 10
2 3 7 11
3 4 8 12
以及数据帧B,它表示A中的列之间的关系:
one two # these get mutated in place
three 1 1
one 0 0
我需要使用它将值与其他列中的值进行就地相乘。输出应为:
one two three
0 9 45 9
1 20 60 10
2 33 77 11
3 48 96 12
因此,在本例中,我对每一行进行了调整:
one *= three
two *= three
对于Pandas / Numpy,有没有一种有效的方法来使用它?
发布于 2013-05-22 10:30:58
看一看here
In [37]: df
Out[37]:
one two three
0 1 5 9
1 2 6 10
2 3 7 11
3 4 8 12
In [38]: df['one'] *= df['three']
In [39]: df['two'] *= df['three']
In [40]: df
Out[40]:
one two three
0 9 45 9
1 20 60 10
2 33 77 11
3 48 96 12
https://stackoverflow.com/questions/16689405
复制相似问题