import csv
with open('in.csv') as infile, open('out.csv', 'wb') as outfile:
reader = csv.reader(infile)
next(reader) # Skip the header
writer = csv.writer(outfile)
writer.writerow(['date', 'time']) # Write the header
for row in reader:
# Remove white spaces in each field and assign to vars
date1, time, date2 = [x.strip() for x in row]
writer.writerow([date1 or date2, time])
1条答案
按热度按时间dxxyhpgq1#
这里有一种方法:
注意事项
date1 or date2
返回其中的非空字符串。