我有一个数据框,我正在尝试使用 xlsxwriter 模块将其写入 Excel 工作表。
下面给出的是我的数据框的样子:
prod_id,prod_name,price,units
prod_a,apple,100,10
prod_b,mango,10,123
prod_c,orange,12,14
我正在尝试将上述数据框编写为如下所示:
# Pulling data for the sheet
row = 1
col = 0
# Iterate through the array you have and unpack the tuple at each index
for elm1, elm2, elm3, elm4 in df:
worksheet.write(row, col, elm1, number_format)
worksheet.write(row, col + 1, elm2, number_format)
worksheet.write(row, col + 2, elm3, number_format)
worksheet.write(row, col + 3, elm4, number_format)
row += 1
它抛出一个错误
for elm1, elm2, elm3, elm4 in df:
ValueError: too many values to unpack (expected 4)
Cats萌萌
相关分类