如何使用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/