我的代码如下:
import scipy.stats as st
DISTRIBUTIONS = [ st.burr,st.cauchy,st.chi,st.chi2,st.cosine,st.dgamma]
for distribution in DISTRIBUTIONS:
params = distribution.fit(df['diff']) #df['diff'] is the data frame column
print ' Generating params for distribution {0}:'.format(distribution)
##Do something further
在print语句的输出中,我没有得到分发名称。相反,我得到scipy对象名称:
Generating params for distribution <scipy.stats._continuous_distns.burr_gen object at 0x7f16d8b9a050>
答案 0 :(得分:2)
scipy.stat
个对象具有name
属性,而是打印出来:
import scipy.stats as st
DISTRIBUTIONS = [ st.burr,st.cauchy,st.chi,st.chi2,st.cosine,st.dgamma]
for distribution in DISTRIBUTIONS:
params = distribution.fit(df['diff']) #df['diff'] is the data frame column
print ' Generating params for distribution {0.name}:'.format(distribution)
##Do something further
示例:
>>> for distro in DISTRIBUTIONS:
... print('{0.name}'.format(distro))
...
burr
cauchy
chi
chi2
cosine
dgamma
答案 1 :(得分:0)
你可以尝试:
import scipy.stats as st
DISTRIBUTIONS = {"burr": st.burr, "cauchy":st.cauchy,"chi":st.chi,"chi2":st.chi2,"cosine":st.cosine,"dgamma":st.dgamma}
for distribution in DISTRIBUTIONS:
params = DISTRIBUTIONS[distribution].fit(df['diff']) #df['diff'] is the data frame column
print ' Generating params for distribution {0}:'.format(distribution)
##Do something further
那会打印出你认为正在寻找的字符串吗?
编辑:其他答案更好。我不知道.name。 :)