我有一个数据框,格式为:
3 -1305.55 -1.638500e+01 -689.773 4.020000e-02
13 2301.26 6.385300e+11 -189.170 1.040270e+06
我无法使用以下格式:
df.to_string(fn, formatters=[" %0.2f ", " %0.5e ", " %0.2f ", " %0.5e"])
我知道了
TypeError: 'str' object is not callable
答案 0 :(得分:2)
正如评论者所述,formatters
必须是可调用对象的列表或字典。使用Python的新格式很容易做到这一点。
print(df.to_string(
formatters=['{:0.2f}'.format, '{:0.5e}'.format, '{:0.2f}'.format, '{:0.5e}'.format]))
0 1 2 3
3 -1305.55 -1.63850e+01 -689.77 4.02000e-02
13 2301.26 6.38530e+11 -189.17 1.04027e+06