我有两个都有句子的变量,然后我想将它们保存到一个新的 excel 文件中,其中每个句子都在不同的列中。我得到一个“列表”对象没有属性“项目”。这是我写的:Use = The dog was sleeping.Strength = The cat was awake.volume = [Use, Strength]!pip install xlsxwriterimport xlsxwriterworkbook = xlsxwriter.Workbook('Jaspersoft.xlsx')worksheet = workbook.add_worksheet()bold = workbook.add_format({'bold': True})worksheet.write('A1', 'Dog', bold)worksheet.write('B1', 'Cat', bold)row = 1col = 0for case, top in volume.items: worksheet.write(row, col, case) worksheet.write(row, col + 1, top) row +=1workbook.close()想要一个有两列标题为 Dog 和 Cat 的 excel 文件,然后在 dog 列下面会有 dog 句子,而 cat 列应该有 cat 句子。
1 回答
喵喔喔
TA贡献1735条经验 获得超5个赞
这应该有效:
Use = "The dog was sleeping."
Strength = "The cat was awake."
volume = [Use, Strength]
!pip install xlsxwriter
import xlsxwriter
workbook = xlsxwriter.Workbook('Jaspersoft.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': True})
worksheet.write('A1', 'Dog', bold)
worksheet.write('B1', 'Cat', bold)
row = 1
col = 0
for i, sentence in enumerate(volume):
worksheet.write(row, col + i, sentence)
row +=1
workbook.close()
添加回答
举报
0/150
提交
取消