简体   繁体   English

如何使用 python 将嵌套列表写入 excel 新行?

[英]How to write a Nested lists into excel new rows using python?

I am new to programming in Python In a part of my code, a list is generated, which itself is a combination of other lists, such as the following output Like the following output, it is generated different times with different data我是编程新手,在Python我的一段代码中,生成了一个列表,它本身就是其他列表的组合,比如下面的output 和下面的output一样,是不同的时间生成不同的数据

1 [['Charles Tao'], ['Sales representative'], ['Zhangtun No.21 Hua er shan village'], ['Tiexi District Pulandian City'], ['Dalian'], ['Liaoning']] 1 [['Charles Tao'], ['Sales representative'], ['Zhangtun No.21 Hua er shan village'], ['Tiexi District Pulandian City'], ['Dalian'], ['Liaoning']]

2 [['JENNY'], ['SALES MANAGER'], ['-'], ['-'], ['Ho Chi Minh'], ['-'], ['-'], ['VIETNAM'], ['vietfoods-ex']] 2 [['JENNY'], ['SALES MANAGER'], ['-'], ['-'], ['Ho Chi Minh'], ['-'], ['-'], ['VIETNAM'], ['vietfoods-ex']]

The data format continues in the same way, although some lists have different lengths数据格式以相同的方式继续,尽管某些列表的长度不同

For example, I used the following two pieces of code, but I did not get the right output比如我用了下面两段代码,都没有得到正确的output

for i in range(1):
      for j in range(0, len(my_list)):
      worksheet.write(i, j, my_list[j][i]) 
    for i in range(0, len(my_list)):
        worksheet.write(0, i, ','.join([str(elem) for elem in my_list[i]]))

I want to save this data in separate rows in an excel file like the attached image here "The points in the first column mean that the rows are continuous"我想将此数据保存在 excel 文件中的单独行中,就像此处的附件“第一列中的点意味着行是连续的”

But every time the data is either not saved or is rewritten on the same data and is duplicate and I have no data in the new row但是每次数据要么没有保存要么被重写在相同的数据上并且是重复的并且我在新行中没有数据

And I do not generate a new row in the Excel file而且我没有在 Excel 文件中生成新行

Thanks if anyone can help and guide me谢谢,如果有人可以帮助和指导我

输出和代码

CODE ITSELF -->代码本身 -->

import xlsxwriter
with xlsxwriter.Workbook('NT.xlsx') as workbook:
    sheet = workbook.add_worksheet()
    row, col = 0, 0
    for line in lines:
         # only write nonempty lines
            sheet.write_row(row, col, line)
            col+=1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Python 在 CSV 中写入新行 - How to write new rows in a CSV using Python 如何使用xlwt包将多个python列表写入Excel文件? - How to write multiple python lists into an excel file using xlwt package? Python:如何将嵌套字典(字典中列表中的字典)写入 excel xlsx 文件 - Python: How to write a nested dictionary (dictionaries in lists in dictionaries) to a excel xlsx file 循环遍历列表以使用 python 在 csv 文件中写入新行的问题 - issue with Looping through lists to write new rows in a csv file using python 如何使用 python 将行写入合并的 excel 模板? - How to write rows to merged excel template by using python? 如何使用Python / Pandas在Excel中插入新行(带条件) - How to Insert New Rows (with a condition) in Excel using Python / Pandas 如何编写嵌套的 python dicts 以在 csv 或 excel 文件中使用制表符和换行符分隔列和行? - How to write nested python dicts to separate columns and rows with tabs and newlines in csv or excel file? 如何在python中编写嵌套列表以表现出色? - How to write nested list to excel in python? 如何在 excel python 列中写入多行? - How to write multiple rows in column excel python? 如何使用 Python 将一个 excel 拆分为多个 excel,并在所有新 excel 中分配相同的行数? - How to split one excel into multiple excel with common number of rows distribution across all the new excel using Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM