python格式化输出到文件

import pandas as pd

x=pd.read_csv(“x.csv”)
for item in [‘nc’,‘vc’,‘ns’,‘vs’]:
x[u’perc’+item] = x[u’perc’+item].apply(lambda t: format(t, ‘.2%’))
print x

f=open(path+“out.txt”,“w”)
for i in x.index:
t=x.iloc[i]
print >> f, t.nc,t.vc,t.ns,t.vs,t.percnc,t.percvc,t.percns,t.percvs
f.close()

你可能感兴趣的:(工具,python)