python - 如何使用python将列表列表写入excel?

标签 python excel python-3.x

如何使用python 3将列表列表写入excel?

new_list = [["first", "second"], ["third", "fourth"]]
with open("file_name.csv", 'w') as f:
    fc = csv.writer(f, lineterminator='\n')
fc.writerows(new_list)
我可以将此列表写入 csv文件,但我怎样才能写在 excel 文件中?

最佳答案

您可以使用 pandas图书馆。

import pandas as pd

new_list = [["first", "second"], ["third", "four"], ["five", "six"]]
df = pd.DataFrame(new_list)
writer = pd.ExcelWriter('test.xlsx', engine='xlsxwriter')
df.to_excel(writer, sheet_name='welcome', index=False)
writer.save()
相关文档:
  • pandas.ExcelWriter
  • pandas.DataFrame
  • pandas.DataFrame.to_excel
  • 关于python - 如何使用python将列表列表写入excel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55508303/

    相关文章:

    python - 如何获取平衡括号组的内容

    python - 在python多处理中获取当前正在执行的输入的索引

    python - 为什么当 python 使用 MySQLdb 时会得到不同的字符集?

    excel - 使条件格式静态化

    excel - 在Excel中检测 "pure"字母

    python - Django-Python3-LDAP 直接绑定(bind)

    python - Django 1.7 从内联表单中删除添加按钮

    python - 使用 Pandas 计算固定时间范围之间的总和

    python - 数字,每个都存储在 1 个数组中

    java - 使用spring hibernate将mysql表导出到excel