因此,我正在尝试将行[0,1,2,9,10]从我已指定为“ e_file”的内容转移到“ no_file”
当我打印“数据”时,会得到我想要的确切信息,我只是想知道如何将这些数据传输到相应的CSV文件?
谢谢。
e_file = '/Users/massive/Desktop//NO/hour.csv'
no_file = '/Users/massive/Desktop/NO/combined.csv'
with open(e_file,'r') as e_r:
state_code = input("Enter state code: ")
county_code = input("Enter county code: ")
station_number = input("Enter station number: ")
csv_reader_2 = csv.reader(e_r)
for row in csv_reader_2:
if row[0] == str(state_code).zfill(2) and row[1] ==str(county_code).zfill(3) and row[2] == str(station_number).zfill(4):
data = [row[0],row[1],row[2],row[9],row[10]]
print(data)
答案 0 :(得分:0)
也许是这样的(除非您提供有效的示例,否则我将无法对其进行测试):
with open(newFile, 'wb') as csvfile:
fwriter = csv.writer(csvfile)
for line in data:
fwriter.writerow(line)