fork download
  1. import csv
  2. import pandas as pd
  3. #文字又は数値を指定幅で結合する
  4. def mix_format(s_list,width):
  5. ostr = ""
  6. fe1 = '{:>' + str(width) + 's}'
  7. fe2 = '{:' + str(width) + 'd}'
  8. for s in s_list:
  9. if type(s) is str:
  10. ostr += fe1.format(s)
  11. else:
  12. ostr += fe2.format(s)
  13. return ostr
  14.  
  15.  
  16. df = pd.read_csv('input.csv', sep=',',header=0)
  17. with open('output.txt',"w") as fw:
  18. line0 = mix_format(list(df.columns),10)
  19. fw.write(line0+'\n') #ヘッダ
  20. for i in df.index: #全行分繰り返す
  21. line1 = mix_format(list(df.iloc[i]),10)
  22. fw.write(line1+'\n') #各行データ
  23.  
  24.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty