我试图用Python计算Brillouin的多样性指数,根据使用pandas和numpy的列“a”。但出了点事。你知道吗
import pandas as pd
import numpy as np
def Brillouin_Index(x):
for i in range(len(x)):
x["Brillouin_Index"] = (np.log10(np.math.factorial(np.sum(x))) - np.sum(np.log10(np.math.factorial(x[i])))) / np.sum(x)
return x
a = list("ABCDEADECS")
b = [12,23,12,12,32,34,21,2,10,5]
c = {"a":a,"b":b}
data = pd.DataFrame(c)
data
data.groupby("a").apply(Brillouin_Index)
我执行了上面的代码,有两个错误。你知道吗
TypeError: cannot convert the series to <class 'int'>
AttributeError: 'int' object has no attribute 'log10'
具体公式见以下链接Brillouin’s Diversity Index
我用其他软件计算每组的数值
非常感谢!你知道吗
我用R来计算布里渊的分集指数组。组代码如下:
相关问题 更多 >
编程相关推荐