Pandas 熊猫-以一根柱子和另一根柱子的圆木为基础

Pandas 熊猫-以一根柱子和另一根柱子的圆木为基础,pandas,numpy,Pandas,Numpy,例如,如果我有: A B 2 4 3 5 6 2 我希望得到以下结果: log 2 (4) log 3 (5) log 6 (2) 我尝试了result=math.log(B,A),但返回的错误为: Cannot convert the series to <type 'float'> 然而,这也产生了同样的错误,不幸的是,要聪明一点。使用日志的属性 np.log(df.B) / np.log(df.A) 0 2.000000 1

例如,如果我有:

A    B    
2    4   
3    5 
6    2
我希望得到以下结果:

log 2 (4)
log 3 (5)
log 6 (2)
我尝试了result=math.log(B,A),但返回的错误为:

Cannot convert the series to <type 'float'>

然而,这也产生了同样的错误,不幸的是,要聪明一点。使用日志的属性

np.log(df.B) / np.log(df.A)

0    2.000000
1    1.464974
2    0.386853
dtype: float64
如果您了解以A为底的B的对数与任何底的
logB/logA
相同,那么这是可行的

作为参考,结果与
math
相同

df.apply(lambda x: math.log(x[1], x[0]), axis=1)

0    2.000000
1    1.464974
2    0.386853
dtype: float64

聪明点。使用日志的属性

np.log(df.B) / np.log(df.A)

0    2.000000
1    1.464974
2    0.386853
dtype: float64
如果您了解以A为底的B的对数与任何底的
logB/logA
相同,那么这是可行的

作为参考,结果与
math
相同

df.apply(lambda x: math.log(x[1], x[0]), axis=1)

0    2.000000
1    1.464974
2    0.386853
dtype: float64

是啊,不公平。忘了基本的日志规则。是的,不公平。忘记了基本的日志规则。