如何循环遍历列表中的每个元素并将其作为 Excel 标题?如果有重复的问题,请告诉我。到目前为止我还没找到。
row=0
col=0
j = 0
title = ['No.', 'Hue', 'Saturation', 'Value',
'Lightness', 'AComponent', 'BComponent',
'Blue Channel', 'Green Channel', 'Red Channel']
for i in title[0:len(title)]:
worksheet.write(row + 1, col + j, 'title[%i]', bold)
j += 1
I wanted to do something like the text in red
您可以使用 Pandas 和 ExcelWriter 模块
使用列表中的列创建空 DF(即您案例中的标题)
import pandas as pd
title = ['No.', 'Hue', 'Saturation', 'Value',
'Lightness', 'AComponent', 'BComponent',
'Blue Channel', 'Green Channel', 'Red Channel']
df = pd.DataFrame(columns = title) #this create your empty data frame
DF 走向卓越
from pandas import ExcelWriter
writer = ExcelWriter('YourCSV.xlsx')
df.to_excel(writer,'Sheet1')
writer.save() #this create Excel file with your desired titles
DF 转 CSV
df.to_csv('YourCSV.csv', sep=',')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)