Python 熊猫:进程单元依赖关系
我是熊猫的新手,所以请容忍我;我有一个数据帧a:Python 熊猫:进程单元依赖关系,python,numpy,pandas,r-factor,Python,Numpy,Pandas,R Factor,我是熊猫的新手,所以请容忍我;我有一个数据帧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
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?看看
这很好,尽管我想我希望有一个解决方案,在我事先不知道依赖关系矩阵的长度的情况下,它不需要Python中的循环。这值得一试吗?顺序重要吗?如果数据帧B中的所有值都是1怎么办?
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