使用 Python 将列表数据添加到 Excel
Add list data into Excel with Python
我有一个格式如下的文件:
2015-11-01|00:00:00|1
2015-11-02|23:00:00|11
2015-11-03|07:00:00|12
2015-11-04|09:00:00|20
我希望能够将这些行转换为列表格式,以便我可以执行如下字段:
for date, hour, count in arr:
incoming_images.write(row, col, date)
incoming_images.write(row, col + 1, hour)
incoming_images.write(row, col + 2, count)
row +=1
我需要帮助弄清楚如何创建这个 "arr"(如果可能的话)。
Str = open("file").read()
lines =Str.count('\n')
Str= Str.replace('\n', '|')
words = Str.split("|")
for i in range(0,len(words)-1,3)
date.append(words[i])
hour.append(words[i+1])
count.append(words[i+2])
for date, hour, count in zip(date,hour,count):
incoming_images.write(row, col, date)
incoming_images.write(row, col + 1, hour)
incoming_images.write(row, col + 2, count)
row +=1
我有一个格式如下的文件:
2015-11-01|00:00:00|1
2015-11-02|23:00:00|11
2015-11-03|07:00:00|12
2015-11-04|09:00:00|20
我希望能够将这些行转换为列表格式,以便我可以执行如下字段:
for date, hour, count in arr:
incoming_images.write(row, col, date)
incoming_images.write(row, col + 1, hour)
incoming_images.write(row, col + 2, count)
row +=1
我需要帮助弄清楚如何创建这个 "arr"(如果可能的话)。
Str = open("file").read()
lines =Str.count('\n')
Str= Str.replace('\n', '|')
words = Str.split("|")
for i in range(0,len(words)-1,3)
date.append(words[i])
hour.append(words[i+1])
count.append(words[i+2])
for date, hour, count in zip(date,hour,count):
incoming_images.write(row, col, date)
incoming_images.write(row, col + 1, hour)
incoming_images.write(row, col + 2, count)
row +=1