python - 通过 Python 2.7 在 .xls 上写入多列

标签 python file excel

    out_file.write('Position'+'\t'+'Hydrophobic'+'\n')

    for i in position:
        out_file.write(str(i)+'\n')
    for j in value:
        out_file.write('\t'+str(j)+'\n')

所以说

Position     Hydrophobic
0            a
1            b
2            c

#... and so on

当它写入Excel文件时,它会将j从值放在i in位置列的底部

如何将它们与“\t”和“\n”并排放置?

最佳答案

for i, j in zip(position, value):
    out_file.write(str(i) + '\t' + str(j) + '\n')

或更好:

     out_file.write('%s\t%s\n' % (str(i), str(j))

或更好:

text = ['%s\t%s' % (str(i), str(j) for i, j in zip(position, value)]
text = '\n'.join(text)
out_file.write(text)

关于python - 通过 Python 2.7 在 .xls 上写入多列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8454543/

相关文章:

mysql - 从文件加载数据到表

确定文件中的一行是否包含阿拉伯数字或罗马数字的 C++ 程序

excel - 焦点矩形出现在 VBA 中的所有列表框项目上

python - 索引numpy数组时numba @njit错误

python - numpy 数组中的多个累积和

python - 如何将 tf.keras 与 bfloat16 结合使用

python - 如何使用python中的map将分类(由字母和数字组成)转换为数字?

java - 使用intent.action.VIEW打开文件时如何获取文件URI?

excel - 计算两列之间的匹配

java - 使用 Cucumber 场景大纲处理 excel 电子表格