繁体   English   中英

如何解决传递给 builtin_function_or_method.__format__ 的不受支持的格式字符串的问题

[英]how to resolve issue with an unsupported format string passed to builtin_function_or_method.__format__

我正在尝试进行标准化(z-score normalization)

x = data[['BALANCE', 'BALANCE_FREQUENCY', 'PURCHASES']]

std_scale = preprocessing.StandardScaler().fit(x)
df_std = std_scale.transform(x)

print('Mean after standardization:\nBALANCE={:.2f}, BALANCE_FREQUENCY={:.2f}, PURCHASES={:.2f}'.format(df_std[:,0].mean(), df_std[:,1].mean, df_std[:,2].mean()))

print('\nStandard deviation after standardization:\nBALANCE={:.2f}, BALANCE_FREQUENCY={:.2f}, PURCHASES={:.2f}'.format(df_std[:,0].std(), df_std[:,1].std, df_std[:,2].std()))

我得到了这个错误:

---> 10       .format(df_std[:,0].mean(), df_std[:,1].mean, df_std[:,2].mean()))
    TypeError: unsupported format string passed to builtin_function_or_method.__format__

您在meanstd的 function 调用中缺少括号。

print('Mean after standardization:\nBALANCE={:.2f}, BALANCE_FREQUENCY={:.2f}, PURCHASES={:.2f}'.format(df_std[:,0].mean(), df_std[:,1].mean(), df_std[:,2].mean()))

print('\nStandard deviation after standardization:\nBALANCE={:.2f}, BALANCE_FREQUENCY={:.2f}, PURCHASES={:.2f}'.format(df_std[:,0].std(), df_std[:,1].std(), df_std[:,2].std()))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM