1
我正在尝试使用行中的其他值为较低置信区间创建一个新列。我已经(作为pypi
上的包public-health-cis
)编写(并发布)置信区间计算。这些函数采用浮点值并返回一个浮点数。将列值传递给Pandas中的lambda函数
在我的分析脚本中,我试图从熊猫数据框中调用这个函数。我尝试了几种方法来试图实现这一目标,但都无济于事。
df_for_ci_calcs = df[['Value', 'Count', 'Denominator']].copy()
df_for_ci_calcs = df_for_ci_calcs.applymap(lambda x: -1 if x == '*' else x)
df_for_ci_calcs = df_for_ci_calcs.astype(np.float)
df['LowerCI'].apply(lambda x: public_health_cis.wilson_lower(df_for_ci_calcs['Value'].astype(float),
df_for_ci_calcs['Count'].astype(float),
df_for_ci_calcs['Denominator'].astype(float), indicator.rate))
这种回溯回来:
Internal Server Error:/
df['LowerCI'].apply(lambda x: public_health_cis.wilson_lower(df_for_ci_calcs['Value'].astype(float), df_for_ci_calcs['Count'].astype(float), df_for_ci_calcs['Denominator'].astype(float), indica
tor.rate))
TypeError: cannot convert the series to <class 'float'>
我一直在使用也尝试:
df['LowerCI'] = df_for_ci_calcs.applymap(lambda x: public_health_cis.wilson_lower(df_for_ci_calcs['Value'], df_for_ci_calcs['Count'],
df_for_ci_calcs['Denominator'], indicator.rate), axis=1)
它提供了错误:
applymap() got an unexpected keyword argument 'axis'
当我将轴kwarg取出时,我得到与第一种方法相同的错误。那么,如何将每行的值传递给函数以获取基于这些行中数据的值?
这就是它谢谢!我觉得自己是一个白痴,没有参考我发送的['Value'],['Count']等,所以我通过整个系列发送,难怪它不喜欢它! – RustyBrain
很高兴能帮到你,祝你好运! – jezrael