的代碼的部分的Excel元值示於下用0填充
import collections
import csv
import sys
with open("321.csv","r") as f:
cr = csv.reader(f,delimiter=",")
d=collections.defaultdict(lambda : list())
header=next(cr) # read title. Retrieve the next item from the iterator by calling its __next__() method.
for r in cr:
d[r[0]].append(r[1]) # fill dict
with open("sorted output.csv","w") as f:
cr = csv.writer(f,sys.stdout, lineterminator='\n')
od = collections.OrderedDict(sorted(d.items()))#sort items based on dictionary key value
for k,v in od.items(): #The method items() returns a list of dict's (key, value) tuple pairs
v = [ord(i) for i in v] # convert letters into numbers
cr.writerow(v)
使我這個輸出:
欲填在該區域的所有空單元:(A1: :X30)用0s(每次應該用0填充的單元格由最大行的長度定義,例如,如果最大的行具有直到Y列的元素,那麼應當填充0的空單元將處於該地區(A1 :: Y30))
你能幫忙嗎?